Skip to content

promise/catch-or-return Restriction

What it does

Ensure that each time a then() is applied to a promise, a catch() is applied as well. Exceptions are made if you are returning that promise.

Why is this bad?

Not catching errors in a promise can cause hard to debug problems or missing handling of error conditions.

Example

Examples of incorrect code for this rule:

javascript
myPromise.then(doSomething);
myPromise.then(doSomething, catchErrors); // catch() may be a little better

Examples of correct code for this rule:

javascript
myPromise.then(doSomething).catch(errors);
function doSomethingElse() {
  return myPromise.then(doSomething);
}

References

Released under the MIT License.