feat: handle http exceptions (#456)

This commit is contained in:
Ahmed Bouhuolia
2024-05-22 19:30:41 +02:00
committed by GitHub
parent 1227111fae
commit 0836fe14e0
14 changed files with 102 additions and 66 deletions

View File

@@ -17,7 +17,9 @@ import {
} from '@/api/middleware/JSONResponseTransformer';
import config from '@/config';
import path from 'path';
import ObjectionErrorHandlerMiddleware from '@/api/middleware/ObjectionErrorHandlerMiddleware';
import { ObjectionErrorException } from '@/api/exceptions/ObjectionErrorException';
import { ServiceErrorException } from '@/api/exceptions/ServiceErrorException';
import { GlobalErrorException } from '@/api/exceptions/GlobalErrorException';
export default ({ app }) => {
// Express configuration.
@@ -30,9 +32,6 @@ export default ({ app }) => {
// Helmet helps you secure your Express apps by setting various HTTP headers.
app.use(helmet());
// Allow to full error stack traces and internal details
app.use(errorHandler());
// Boom response objects.
app.use(boom());
@@ -65,8 +64,10 @@ export default ({ app }) => {
// Agendash application load.
app.use('/agendash', AgendashController.router());
// Handles objectionjs errors.
app.use(ObjectionErrorHandlerMiddleware);
// Handles errors.
app.use(ObjectionErrorException);
app.use(ServiceErrorException);
app.use(GlobalErrorException);
// catch 404 and forward to error handler
app.use((req: Request, res: Response, next: NextFunction) => {