Skip to main content

prefer-promise-reject-errors

It’s good practice to only reject Promises with Error objects. Errors automatically store stack traces for debugging.
Rule Type: Suggestion
Fixable: No

Why This Rule Exists

Error objects provide:
  • Stack traces: See where rejection occurred
  • Standard format: Consistent error handling
  • Type checking: Can check if value is Error
  • Better debugging: Shows full call stack
Without Error objects, debugging is much harder.

Rule Details

This rule enforces that Promises are only rejected with Error objects.

Examples

Incorrect Code

Correct Code

Options

allowEmptyReject

Type: boolean
Default: false
Allow Promise.reject() with no arguments.
With allowEmptyReject: true

Benefits of Error Objects

Stack Traces

Error objects capture where they were created, making debugging much easier.

Type Checking

Error Logging Services

Common Patterns

API Errors

Validation Errors

Timeout Errors

Custom Error Types

Extending Error

Known Limitations

This rule uses static analysis and cannot guarantee that you only reject with Errors:

Async Functions

This rule doesn’t check throw in async functions (they become rejections), but no-throw-literal does:

Configuration

When Not to Use It

Disable if you intentionally reject with non-Error values. However, this makes debugging harder and is generally not recommended.

Further Reading