update error handler
This commit is contained in:
1 parent
1defa52ae8
commit
f09f0630dc
1 file changed
+2
-2
@@ -4,14 +4,14 @@ import { AppError } from "@/utils/AppError.js";
|
|||||||
|
|
||||||
const handleErrors = (error: unknown, req: Request, res: Response, _next: NextFunction) => {
|
const handleErrors = (error: unknown, req: Request, res: Response, _next: NextFunction) => {
|
||||||
const status = error instanceof AppError ? error.status || 500 : 500;
|
const status = error instanceof AppError ? error.status || 500 : 500;
|
||||||
const message = error instanceof AppError ? error.message : "Server error";
|
const message = error instanceof AppError ? error.message : error instanceof Error ? error.message : "Server error";
|
||||||
const service = error instanceof AppError ? error.service : "unknownService";
|
const service = error instanceof AppError ? error.service : "unknownService";
|
||||||
const method = error instanceof AppError ? error.method : "unknownMethod";
|
const method = error instanceof AppError ? error.method : "unknownMethod";
|
||||||
logger.error({
|
logger.error({
|
||||||
message: message,
|
message: message,
|
||||||
service: service,
|
service: service,
|
||||||
method: method,
|
method: method,
|
||||||
stack: error instanceof AppError ? error.stack : undefined,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
details: error instanceof AppError ? error.details : undefined,
|
details: error instanceof AppError ? error.details : undefined,
|
||||||
});
|
});
|
||||||
res.status(status).json({
|
res.status(status).json({
|
||||||
|
|||||||
Reference in new issue
Block a user