Error Classify And Map

Classify errors by type and map to appropriate HTTP status codes with retry decisions for API layers.

TypescriptResilience

Code

snippet
export class AppError extends Error{constructor(message:string,public statusCode:number=500,public isRetryable:boolean=false){super(message);this.name='AppError';}}export class ValidationError extends AppError{constructor(message:string){super(message,400,false);this.name='ValidationError';}}export class NotFoundError extends AppError{constructor(message:string){super(message,404,false);this.name='NotFoundError';}}export function classifyError(e:unknown):AppError{if(e instanceof AppError)return e;if(e instanceof TypeError)return new AppError('type error',400,false);return new AppError('internal error',500,true);}export function shouldRetry(e:unknown):boolean{return classifyError(e).isRetryable;}