diff --git a/lib/middleware/onerror.js b/lib/middleware/onerror.js index dffbb6a3be457b..af44c84857380c 100644 --- a/lib/middleware/onerror.js +++ b/lib/middleware/onerror.js @@ -39,8 +39,10 @@ module.exports = async (ctx, next) => { }); } } catch (err) { - if (err instanceof Error && !err.stack.split('\n')[0].includes('lib/middleware/parameter.js')) { + if (err instanceof Error && !err.stack.split('\n')[1].includes('lib/middleware/parameter.js')) { // Append v2 route path if a route throws an error + // since koa-mount will remove the mount path from ctx.request.path + // https://github.com/koajs/mount/issues/62 ctx.request.path = (ctx.mountPath ?? '') + ctx.request.path; ctx._matchedRoute = ctx._matchedRoute ? (ctx.mountPath ?? '') + ctx._matchedRoute : ctx.request.path; } diff --git a/test/router.js b/test/router.js index 26bead6e58d2f8..91c1db2d1435fc 100644 --- a/test/router.js +++ b/test/router.js @@ -17,7 +17,7 @@ async function checkRSS(response) { expect(date).toEqual(expect.any(String)); expect(Date.parse(date)).toEqual(expect.any(Number)); expect(new Date() - new Date(date)).toBeGreaterThan(-1000 * 60 * 60 * 24 * 5); - expect(new Date() - new Date(date)).toBeLessThan(1000 * 60 * 60 * 24 * 30 * 12 * 5); + expect(new Date() - new Date(date)).toBeLessThan(1000 * 60 * 60 * 24 * 30 * 12 * 10); }; const parsed = await parser.parseString(response.text);