Creates a new AppError instance with structured error information
This constructor automatically sets the error as operational and captures the stack trace for debugging purposes. The error will be properly handled by the global error handler middleware.
Human-readable error message describing what went wrong
HTTP status code (e.g., 400, 401, 403, 404, 500)
Application-specific error code from ErrorCodes enum
HTTP status code to be returned to the client
Application-specific error code for categorization and client-side handling
Flag indicating this is an expected operational error, not a system failure Operational errors are expected and should be handled gracefully by the application
Custom Application Error Class for WayrApp Backend
A specialized error class that extends the native JavaScript Error to provide structured error handling throughout the WayrApp language learning platform. This class standardizes error representation by including HTTP status codes, application-specific error codes, and operational flags that help distinguish between expected application errors and unexpected system failures.
The AppError class is designed to work seamlessly with the errorHandler middleware, providing a consistent error format across all API endpoints. It supports the application's evolution toward a distributed architecture where standardized error handling becomes critical for inter-node communication and debugging across multiple services.
This error class is used throughout the application for throwing predictable, well-structured errors that can be properly handled by the error middleware and returned to clients in a consistent format. It's particularly useful for validation errors, authentication failures, authorization issues, and business logic violations.
Key Features:
Usage Patterns:
Example
Example
Example
Example