Browse Source

Document how to test for cancelation (#376)

no-retry
Damien Lebrun 7 years ago
committed by Sindre Sorhus
parent
commit
5d4521836e
  1. 16
      readme.md

16
readme.md

@ -280,7 +280,21 @@ When given an unsupported protocol.
## Aborting the request
The promise returned by Got has a `.cancel()` function which, when called, aborts the request.
The promise returned by Got has a [`.cancel()`](https://github.com/sindresorhus/p-cancelable) method which, when called, aborts the request.
```js
const request = got(url, options);
request.catch(err => {
if (request.canceled) {
// Handle cancelation
}
// Handle other errors
});
request.cancel();
```
## Proxies

Loading…
Cancel
Save