summary refs log tree commit diff
path: root/src/api/middlewares/ErrorHandler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/middlewares/ErrorHandler.ts')
-rw-r--r--src/api/middlewares/ErrorHandler.ts7
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`,