import { HTTPStatus } from 'deps'; import { logger } from 'infra/logger.ts'; import Controller from 'if/controllers/controller.class.ts'; function notFoundController(): Controller { const controller = new Controller(); controller.setHandler('*', '*', (req: Request) => { return controller.response(req, 'not found', { status: HTTPStatus.NotFound, }); }); return controller; } function internalServerErrorController(): Controller { const controller = new Controller(); controller.setHandler('*', '*', (req: Request, error?: string) => { if (error) { logger.error(error); } return controller.response(req, 'internal server error', { status: HTTPStatus.InternalServerError, }); }); return controller; } function handle(errorController: Controller, req: Request, error?: string) { return errorController.getHandler('*', '*')(req, error); } export const ControllerErrors = { NotFound: (req: Request) => handle(notFoundController(), req), InternalServerError: (req: Request, error: string) => handle(internalServerErrorController(), req, error), };