Extended Error interface with optional HTTP status code support. This enables consistent error handling with status codes across the application.
throw Object.assign(new Error('User not found'), { status: 404 });// Or with custom class:class ApiError extends Error implements ErrorWithStatus { constructor(message: string, public status?: number) { super(message); }} Copy
throw Object.assign(new Error('User not found'), { status: 404 });// Or with custom class:class ApiError extends Error implements ErrorWithStatus { constructor(message: string, public status?: number) { super(message); }}
Optional
HTTP status code associated with the error (e.g., 400, 404, 500)
Extended Error interface with optional HTTP status code support. This enables consistent error handling with status codes across the application.
Example