prefer-promise-reject-errors
Configuration
rslint.config.ts
Rule Details
This rule requires that Promises are rejected with Error objects only. Rejecting with non-Error values (such as strings or numbers) makes debugging harder because the rejection reason does not carry a stack trace.
The rule flags two patterns:
Promise.reject(value)calls wherevaluecannot be anError.new Promise((resolve, reject) => { ... })executors where the second parameter is invoked with a value that cannot be anError.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
This rule accepts an options object with the following property:
allowEmptyReject(boolean, defaultfalse) — whentrue, allows calls toPromise.reject()and the executor's reject callback with no arguments.
Examples of correct code for this rule with { "allowEmptyReject": true }: