feat: incorporate NotAuthorized error in error handler

This commit is contained in:
Ali BARIN
2024-08-29 14:19:17 +00:00
parent 01340f4597
commit 7a54ff212e
4 changed files with 16 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ import objection from 'objection';
import * as Sentry from './sentry.ee.js';
const { NotFoundError, DataError, ValidationError, UniqueViolationError } =
objection;
import NotAuthorizedError from '../errors/not-authorized.js';
import HttpError from '../errors/http.js';
import {
renderObjectionError,
@@ -43,6 +44,10 @@ const errorHandler = (error, request, response, next) => {
response.status(200).json(httpErrorPayload);
}
if (error instanceof NotAuthorizedError) {
response.status(403).end();
}
const statusCode = error.statusCode || 500;
logger.error(request.method + ' ' + request.url + ' ' + statusCode);