From 5d4521836e4528b085c737dfd50a66b141479285 Mon Sep 17 00:00:00 2001 From: Damien Lebrun Date: Fri, 22 Sep 2017 06:47:53 +0100 Subject: [PATCH] Document how to test for cancelation (#376) --- readme.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 74d6f66..e4447d3 100644 --- a/readme.md +++ b/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