Skip to content

Commit 6b2a3ac

Browse files
committed
fix: catch custom 400 errors emitted by koa-bodyparser
1 parent 53ea9ab commit 6b2a3ac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/middleware.ts

+13
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ export const jsonApiErrorMiddleware = (options?: ErrorMiddlewareOptions): Middle
8181
return;
8282
}
8383

84+
if (error instanceof Error && "status" in error && error.status === 400) {
85+
context.status = 400;
86+
context.body = new JsonApiErrorBody({
87+
status: "400",
88+
code: "bad_request",
89+
title: "Bad Request",
90+
detail: error.message,
91+
});
92+
93+
options?.logError?.(error, true);
94+
return;
95+
}
96+
8497
context.status = 500;
8598
context.body = new JsonApiErrorBody({
8699
status: "500",

0 commit comments

Comments
 (0)