From ad2e96706831ec9364320d7c6417eba97c55c41e Mon Sep 17 00:00:00 2001 From: TonyRL Date: Tue, 5 Dec 2023 21:54:24 +0000 Subject: [PATCH] fix(core): double namespace if the error is thrown from parameter --- lib/middleware/onerror.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/middleware/onerror.js b/lib/middleware/onerror.js index a29f59b7a74433..dffbb6a3be457b 100644 --- a/lib/middleware/onerror.js +++ b/lib/middleware/onerror.js @@ -39,9 +39,11 @@ module.exports = async (ctx, next) => { }); } } catch (err) { - // Append v2 route path - ctx.request.path = (ctx.mountPath ?? '') + ctx.request.path; - ctx._matchedRoute = ctx._matchedRoute ? (ctx.mountPath ?? '') + ctx._matchedRoute : ctx.request.path; + if (err instanceof Error && !err.stack.split('\n')[0].includes('lib/middleware/parameter.js')) { + // Append v2 route path if a route throws an error + ctx.request.path = (ctx.mountPath ?? '') + ctx.request.path; + ctx._matchedRoute = ctx._matchedRoute ? (ctx.mountPath ?? '') + ctx._matchedRoute : ctx.request.path; + } let message = err; if (err.name && (err.name === 'HTTPError' || err.name === 'RequestError')) {