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

chore(guide): fulfil error handler and trailers #4087

Merged
merged 4 commits into from
Jun 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 40 additions & 1 deletion docs/Guides/Migration-Guide-V4.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,39 @@ work after upgrading.

## Breaking Changes

### Deprecation of `app.use()`
### Error handling composition ([#3261](https://github.com/fastify/fastify/pull/3261))

When an error is thrown in a async error handler function,
the upper-level error handler is executed if set.
If there is not a upper-level error handler, the default will
be executed as it was previously.

```
import Fastify from 'fastify'

const fastify = Fastify()

fastify.register(async fastify => {
fastify.setErrorHandler(async err => {
console.log(err.message) // 'kaboom'
throw new Error('caught')
})

fastify.get('/encapsulated', async () => {
throw new Error('kaboom')
})
})

fastify.setErrorHandler(async err => {
console.log(err.message) // 'caught'
throw new Error('wrapped')
})

const res = await fastify.inject('/encapsulated')
console.log(res.json().message) // 'wrapped'
```

### Deprecation of `app.use()` ([#3506](https://github.com/fastify/fastify/pull/3506))

Starting this version of Fastify, we have deprecated the use of `app.use()`. We
have decided not to support the use of middlewares. Both
Expand Down Expand Up @@ -70,3 +102,10 @@ properties: {
}
}
```

### Add `reply.trailers` methods ([#3794](https://github.com/fastify/fastify/pull/3794))

Fastify now supports the [HTTP Trailer] response headers.


[HTTP Trailer]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer