From 0403ef69e647e5811a05ac1a7de9bab59a8f4b8a Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 14 May 2024 09:52:46 +0800 Subject: [PATCH] fix: only set err.status on statusCode >= 200 --- app/port/middleware/ErrorHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/port/middleware/ErrorHandler.ts b/app/port/middleware/ErrorHandler.ts index 0453b053..f8c5bf8c 100644 --- a/app/port/middleware/ErrorHandler.ts +++ b/app/port/middleware/ErrorHandler.ts @@ -31,7 +31,7 @@ export async function ErrorHandler(ctx: EggContext, next: Next) { } // http status, default is DEFAULT_SERVER_ERROR_STATUS - ctx.status = err.status || DEFAULT_SERVER_ERROR_STATUS; + ctx.status = (typeof err.status === 'number' && err.status >= 200) ? err.status : DEFAULT_SERVER_ERROR_STATUS; // don't log NotImplementedError if (ctx.status >= DEFAULT_SERVER_ERROR_STATUS && err.name !== 'NotImplementedError') { ctx.logger.error(err);