From 9e67f2760246fcf17ef80c437c87f5435454cc43 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Tue, 8 Oct 2024 10:14:21 +0800 Subject: [PATCH] fix(core): expose syntax error response (#6646) expose syntax error response --- packages/core/src/middleware/koa-error-handler.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/src/middleware/koa-error-handler.ts b/packages/core/src/middleware/koa-error-handler.ts index da8a32154..7ed7d7567 100644 --- a/packages/core/src/middleware/koa-error-handler.ts +++ b/packages/core/src/middleware/koa-error-handler.ts @@ -44,6 +44,13 @@ export default function koaErrorHandler(): Middleware< return; } + // Expose JSON body parsing errors + if (error instanceof SyntaxError) { + ctx.status = 400; + ctx.body = { message: error.message }; + return; + } + // Should log 500 errors in prod anyway if (EnvSet.values.isProduction) { consoleLog.error(error);