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')) {