Skip to main content
Feathers provides a comprehensive set of error classes that map to HTTP status codes and can be used throughout your application for consistent error handling.

FeathersError Class

All Feathers errors extend the base FeathersError class:
index.ts:17-65

Creating Errors

Error Serialization

Errors automatically serialize to JSON:
index.ts:47-64

Built-in Error Types

Feathers includes error classes for all common HTTP status codes:

Client Errors (4xx)

index.ts:67-71

Server Errors (5xx)

index.ts:157-162

Complete List

index.ts:221-256

Using Errors in Services

Throwing Errors

Error Hooks

Handle errors using error hooks:

Application-Level Error Handling

Recovering from Errors

Error hooks can recover from errors by setting context.result:

Error Conversion

Convert non-Feathers errors to FeathersError:
index.ts:258-273

Validation Errors

Structure validation errors for clarity:

Database Error Handling

Transform database errors to Feathers errors:

Real-World Patterns

Authentication Errors

Authorization Errors

Rate Limiting Errors

Error Logging

Client-Side Error Handling

Best Practices

  1. Use appropriate error types - Choose the most specific error class
  2. Include helpful messages - Make error messages clear and actionable
  3. Add context with data - Include relevant information in data property
  4. Handle errors at the right level - Service-level vs application-level
  5. Log errors properly - Include enough context for debugging
  6. Transform technical errors - Convert database/API errors to user-friendly messages
  7. Validate early - Catch errors in before hooks before hitting the database
  8. Don’t leak sensitive info - Be careful what you include in error messages

Next Steps

Hooks

Learn more about error hooks

Validation

Implement comprehensive validation