Skip to content

Commit

Permalink
docs(client-aborted): remove deprecated function (#4898)
Browse files Browse the repository at this point in the history
[request.aborted](https://nodejs.org/docs/latest-v16.x/api/http.html#requestaborted)
has been deprecated since node 16.
It seems like [request.destroyed](https://nodejs.org/docs/latest-v16.x/api/http.html#requestdestroyed)
should be used instead
  • Loading branch information
JekRock committed Jul 14, 2023
1 parent 1c50da3 commit cc347d7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/Guides/Detecting-When-Clients-Abort.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const app = Fastify({

app.addHook('onRequest', async (request, reply) => {
request.raw.on('close', () => {
if (request.raw.aborted) {
if (request.raw.destroyed) {
app.log.info('request closed')
}
})
Expand Down Expand Up @@ -85,7 +85,7 @@ functionality:
of `{ ok: true }`.
- An onRequest hook that triggers when every request is received.
- Logic that triggers in the hook when the request is closed.
- Logging that occurs when the closed request property `aborted` is true.
- Logging that occurs when the closed request property `destroyed` is true.

In the request close event, you should examine the diff between a successful
request and one aborted by the client to determine the best property for your
Expand All @@ -97,7 +97,7 @@ You can also perform this logic outside of a hook, directly in a specific route.
```js
app.get('/', async (request, reply) => {
request.raw.on('close', () => {
if (request.raw.aborted) {
if (request.raw.destroyed) {
app.log.info('request closed')
}
})
Expand All @@ -112,7 +112,7 @@ aborted and perform alternative actions.
```js
app.get('/', async (request, reply) => {
await sleep(3000)
if (request.raw.aborted) {
if (request.raw.destroyed) {
// do something here
}
await sleep(3000)
Expand Down

0 comments on commit cc347d7

Please sign in to comment.