Skip to content

Commit 0a4d2fa

Browse files
brettz9MichaelDeBoey
authored andcommitted
docs(catch-or-return): improve docs re: allowThen option
1 parent 7d46b3b commit 0a4d2fa

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

docs/rules/catch-or-return.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,28 @@ function doSomethingElse() {
3232

3333
##### `allowThen`
3434

35-
You can pass an `{ allowThen: true }` as an option to this rule to allow for
36-
`.then(null, fn)` to be used instead of `catch()` at the end of the promise
37-
chain.
35+
The second argument to `then()` can also be used to handle a promise rejection,
36+
but it won't catch any errors from the first argument callback. Because of this,
37+
this rule reports usage of `then()` with two arguments without `catch()` by
38+
default.
39+
40+
However, you can use `{ allowThen: true }` to allow using `then()` with two
41+
arguments instead of `catch()` to handle promise rejections.
42+
43+
Examples of **incorrect** code for the default `{ allowThen: false }` option:
44+
45+
```js
46+
myPromise.then(doSomething, handleErrors)
47+
myPromise.then(null, handleErrors)
48+
```
49+
50+
Examples of **correct** code for the `{ allowThen: true }` option:
51+
52+
```js
53+
myPromise.then(doSomething, handleErrors)
54+
myPromise.then(null, handleErrors)
55+
myPromise.then(doSomething).catch(handleErrors)
56+
```
3857

3958
##### `allowFinally`
4059

0 commit comments

Comments
 (0)