Skip to content

Commit

Permalink
docs: update setErrorHandler to explain not found behaviour (#5218)
Browse files Browse the repository at this point in the history
* docs: add note to setErrorHandler explaining not found behaviour

Coming from other frameworks this is somewhat surprising. This documents the behaviour and explains to catch 404 errors users need to set a not found handler.

* Replace note blocks with bulleted list
  • Loading branch information
domdomegg committed Dec 24, 2023
1 parent b834ac7 commit 0c86bb4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/Reference/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -1532,9 +1532,11 @@ handlers. *async-await* is supported as well.
If the error `statusCode` is less than 400, Fastify will automatically
set it to 500 before calling the error handler.

> **Note**
> `setErrorHandler` will ***not*** catch any error inside
> an `onResponse` hook because the response has already been sent to the client.
`setErrorHandler` will ***not*** catch:
- errors thrown in an `onResponse` hook because the response has already been
sent to the client. Use the `onSend` hook instead.
- not found (404) errors. Use [`setNotFoundHandler`](#set-not-found-handler)
instead.

```js
fastify.setErrorHandler(function (error, request, reply) {
Expand Down

0 comments on commit 0c86bb4

Please sign in to comment.