/** * An error from a service (src/services/*) with the HTTP status it means. v2 turns it into its * error shape by the status (v2/errors.ts); v1 controllers keep answering as they always did. */ export class ServiceError extends Error { readonly statusCode: number; /** Extra, e.g. couponError or a code the caller can switch on. */ readonly code?: string; constructor(statusCode: number, message: string, code?: string) { super(message); this.statusCode = statusCode; this.code = code; } } export const fail = (statusCode: number, message: string, code?: string): never => { throw new ServiceError(statusCode, message, code); };