-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# β Houston | ||
|
||
> RFC 7807 compliant errors for Node.js | ||
[![npm](https://img.shields.io/npm/v/moducate/houston)](https://npmjs.com/package/moducate/houston) | ||
[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainabilitymoducate/houston)](https://codeclimate.com/github/moducate/houston) | ||
[![npms.io (quality)](https://img.shields.io/npms-io/final-score/moducate/houston?label=npms.io%20score)](https://api.npms.io/v2/package/moducate/houston) | ||
[![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@moducate/houston)](#) | ||
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/moducate/houston)](https://bundlephobia.com/package/moducate/houston) | ||
|
||
- π **Fully compliant.** Fully compliant with the [RFC 7807 specification](https://datatracker.ietf.org/doc/html/rfc7807). | ||
- π‘ **Lightweight.** | ||
- πͺ **TypeScript.** Fully typed and self-documenting! | ||
|
||
## π Quick Start | ||
|
||
### Install | ||
|
||
```bash | ||
# npm | ||
npm i @moducate/houston | ||
|
||
# or yarn | ||
yarn add @moducate/houston | ||
``` | ||
|
||
### Import | ||
|
||
```js | ||
// ESM / TypeScript | ||
import { withError } from "@moducate/houston"; | ||
|
||
// or CommonJS | ||
const { withError } = require("@moducate/houston"); | ||
``` | ||
|
||
### Example Usage | ||
|
||
Transform an `express` response: | ||
|
||
```js | ||
const { withError } = require("@moducate/houston"); | ||
const app = require("express")(); | ||
|
||
app.get("/not-found", (_, res) => { | ||
return withError(res, { type: "https://example.com/not-found", status: 404 }) | ||
}); | ||
``` | ||
|
||
## π· MIME Type | ||
|
||
The exported `mime` constant can be used to obtain the media/MIME type for RFC 7807 JSON errors. | ||
|
||
```js | ||
const { mime } = require("@moducate/houston"); | ||
|
||
console.log(mime); | ||
// => 'application/problem+json' | ||
``` | ||
|
||
This is what the `Content-Type` header of the response supplied to `withError` is set to. | ||
|
||
## β License | ||
|
||
Houston is licensed under the [`MIT License`](LICENSE). |