log errors

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-13 15:42:11 +02:00
parent 4e0ec23f09
commit b9fe6127ff

View File

@@ -4,9 +4,14 @@ import { MixanErrorResponse } from "@mixan/types";
export const errorHandler = (error: HttpError | Error, req: Request, res: Response, next: NextFunction) => {
if(error instanceof HttpError) {
console.log('[HttpError]', error.toJson())
return res.status(error.status).json(error.toJson())
}
console.log('[UnknownError]', error.name, error.message)
if(error.stack) {
console.log(error.stack)
}
return res.status(500).json({
code: 500,
status: 'error',