diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-04-16 21:46:50 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-04-16 21:46:50 +1000 |
commit | 164fcc25f3dd0059cd630a6967d3fe199277d8f6 (patch) | |
tree | 878916e9353f9b5b71cc71ee7c6eff30ea8d9fde /src/api/middlewares | |
parent | fix style action (diff) | |
download | server-164fcc25f3dd0059cd630a6967d3fe199277d8f6.tar.xz |
Fix body-parser errors not being filtered in ErrorHandler middleware
Diffstat (limited to 'src/api/middlewares')
-rw-r--r-- | src/api/middlewares/ErrorHandler.ts | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/api/middlewares/ErrorHandler.ts b/src/api/middlewares/ErrorHandler.ts index b8a73298..c417e64f 100644 --- a/src/api/middlewares/ErrorHandler.ts +++ b/src/api/middlewares/ErrorHandler.ts @@ -22,7 +22,7 @@ import { ApiError, FieldError } from "@spacebar/util"; const EntityNotFoundErrorRegex = /"(\w+)"/; export function ErrorHandler( - error: Error, + error: Error & { type?: string }, req: Request, res: Response, next: NextFunction, @@ -50,6 +50,11 @@ export function ErrorHandler( code = Number(error.code); message = error.message; errors = error.errors; + } else if (error?.type == "entity.parse.failed") { + // body-parser failed + httpcode = 400; + code = 50109; + message = "The request body contains invalid JSON."; } else { console.error( `[Error] ${code} ${req.url}\n`, |