import { Context } from 'hono'; import { HTTPException } from 'hono/http-exception'; export class AppError extends Error { constructor( public code: number, message: string, public status: number = 400 ) { super(message); this.name = 'AppError'; } } export function errorHandler(err: Error, c: Context) { if (err instanceof AppError) { return c.json( { code: err.code, data: null, message: err.message }, err.status as any ); } if (err instanceof HTTPException) { return c.json( { code: err.status * 100, data: null, message: err.message }, err.status ); } console.error('Unhandled error:', err); return c.json( { code: 50001, data: null, message: 'Internal server error' }, 500 ); }