import { Context } from '../context'; export const ErrorHandler = Symbol('ErrorHandler'); export const ErrorMessageResolver = Symbol('ErrorMessageResolver'); export const DEFAULT_ERROR_HANDLER_PRIORITY = 1; export const HTTP_ERROR_HANDLER_PRIORITY = DEFAULT_ERROR_HANDLER_PRIORITY + 100; export const VALIDATION_ERRORS_ERROR_HANDLER_PRIORITY = HTTP_ERROR_HANDLER_PRIORITY + 100; export interface ErrorHandler { /** * The priority value must be greater than the default Error Handler's priority: DEFAULT_ERROR_HANDLER_PRIORITY, otherwise it will never be executed. */ readonly priority: number; canHandle(ctx: Context, err: Error): Promise; handle(ctx: Context, err: Error): Promise; } /** What the client is told about an error. */ export interface ErrorResponse { status: number; message: string; } /** Decides the status and the message an error answers with; error handlers and the mvc JSON view use it. */ export interface ErrorMessageResolver { resolve(error: unknown): ErrorResponse; }