Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(readme): add error code documentation #300

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,17 @@ fastify.post('/sign/:namespace', async function (request, reply) {
For your convenience, you can override the default HTTP response messages sent when an unauthorized or bad request error occurs. You can choose the specific messages to override and the rest will fallback to the default messages. The object must be in the format specified in the example below.

#### Example

```js
const fastify = require('fastify')

const myCustomMessages = {
badRequestErrorMessage: 'Format is Authorization: Bearer [token]',
badCookieRequestErrorMessage: 'Cookie could not be parsed in request',
noAuthorizationInHeaderMessage: 'Autorization header is missing!',
noAuthorizationInHeaderMessage: 'No Authorization was found in request.headers',
noAuthorizationInCookieMessage: 'No Authorization was found in request.cookies',
authorizationTokenExpiredMessage: 'Authorization token expired',
authorizationTokenUntrusted: 'Untrusted authorization token',
authorizationTokenUnsigned: 'Unsigned authorization token
authorizationTokenUnsigned: 'Unsigned authorization token'
// for the below message you can pass a sync function that must return a string as shown or a string
authorizationTokenInvalid: (err) => {
return `Authorization token is invalid: ${err.message}`
Expand All @@ -500,6 +499,44 @@ fastify.register(require('@fastify/jwt'), {
})
```

##### Error Code

`ERR_ASSERTION` - Missing required parameter or option
* Error Status Code: `500`
* Error Message: `Missing ${required}`

`FST_JWT_BAD_REQUEST` - Bad format in request authorization header. Example of correct format `Authorization: Bearer [token]`
* Error Status Code: `400`
* Error Message: `Format is Authorization: Bearer [token]`

`FST_JWT_BAD_COOKIE_REQUEST` - Cookie could not be parsed in request object
* Error Status Code: `400`
* Error Message: `Cookie could not be parsed in request`

`FST_JWT_NO_AUTHORIZATION_IN_HEADER` - No Authorization header was found in request.headers
* Error Status Code: `401`
* Error Message: `No Authorization was found in request.headers

`FST_JWT_NO_AUTHORIZATION_IN_COOKIE` - No Authorization header was found in request.cookies
* Error Status Code: `401`
* Error Message: `No Authorization was found in request.cookies`

`FST_JWT_AUTHORIZATION_TOKEN_EXPIRED` - Authorization token has expired
* Error Status Code: `401`
* Error Message: `Authorization token expired`

`FST_JWT_AUTHORIZATION_TOKEN_INVALID` - Authorization token provided is invalid.
* Error Status Code: `401`
* Error Message: `Authorization token is invalid: ${err.message}`

`FST_JWT_AUTHORIZATION_TOKEN_UNTRUSTED` - Untrusted authorization token was provided
* Error Status Code: `401`
* Error Message: `Untrusted authorization token`

`FAST_JWT_MISSING_SIGNATURE` - Unsigned or missing authorization token
* Error Status Code: `401`
* Error Message: `Unsigned authorization token`

### `decoratorName`
If this plugin is used together with fastify/passport, we might get an error as both plugins use the same name for a decorator. We can change the name of the decorator, or `user` will default

Expand Down