diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-17 20:37:13 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-17 20:37:13 +0200 |
commit | 70d9aa669e48bcc225c8afa2790fe57151c99277 (patch) | |
tree | fb2ccfd601384a8c4bc77220bbd95db78f1f28d5 /api/src/middlewares | |
parent | :bug: fix login route (diff) | |
download | server-70d9aa669e48bcc225c8afa2790fe57151c99277.tar.xz |
:loud_sound: verbose error handler
Diffstat (limited to 'api/src/middlewares')
-rw-r--r-- | api/src/middlewares/ErrorHandler.ts | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/api/src/middlewares/ErrorHandler.ts b/api/src/middlewares/ErrorHandler.ts index 04d56026..d080e498 100644 --- a/api/src/middlewares/ErrorHandler.ts +++ b/api/src/middlewares/ErrorHandler.ts @@ -3,6 +3,8 @@ import { HTTPError } from "lambert-server"; import { FieldError } from "../util/instanceOf"; export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) { + if (!error) next(); + try { let code = 400; let httpcode = code; @@ -24,9 +26,11 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne if (httpcode > 511) httpcode = 400; + console.error(`[Error] ${code} ${req.url} ${message}`, errors || error); + res.status(httpcode).json({ code: code, message, errors }); } catch (error) { - console.error(error); + console.error(`[Internal Server Error] 500`, error); return res.status(500).json({ code: 500, message: "Internal Server Error" }); } } |