Skip to content

Commit

Permalink
Mention how to abort the request using hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Nov 4, 2019
1 parent d520a3a commit 96ea75f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions readme.md
Expand Up @@ -927,6 +927,28 @@ The promise returned by Got has a [`.cancel()`](https://github.com/sindresorhus/
})();
```

When using hooks, simply throw an error to abort the request.

```js
(async () => {
const request = got(url, {
hooks: {
beforeRequest: [
() => {
throw new Error('Oops. Request canceled.');
}
]
}
});

try {
await request;
} catch (error) {
//
}
})();
```

<a name="cache-adapters"></a>
## Cache

Expand Down

0 comments on commit 96ea75f

Please sign in to comment.