change: 401 logging

This commit is contained in:
Julian Krauser 2025-01-09 12:34:05 +01:00
parent 03cc0f02b7
commit c6005af51e

View file

@ -1,6 +1,7 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { ExceptionBase } from "../exceptions/exceptionsBaseType"; import { ExceptionBase } from "../exceptions/exceptionsBaseType";
import CustomRequestException from "../exceptions/customRequestException"; import CustomRequestException from "../exceptions/customRequestException";
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
export default function errorHandler(err: ExceptionBase | Error, req: Request, res: Response, next: Function) { export default function errorHandler(err: ExceptionBase | Error, req: Request, res: Response, next: Function) {
let status = 500; let status = 500;
@ -10,8 +11,11 @@ export default function errorHandler(err: ExceptionBase | Error, req: Request, r
status = err.statusCode; status = err.statusCode;
msg = err.message; msg = err.message;
} }
if (err instanceof UnauthorizedRequestException) {
console.log("Handler", err); console.log("Unauthorized Requests Detected", err.message);
} else {
console.log("Handler", err);
}
res.status(status).send(msg); res.status(status).send(msg);
} }