const logger = require('@/utils/logger'); module.exports = async (ctx, next) => { try { await next(); } catch (err) { logger.error(`Error in ${ctx.request.path}: ${err instanceof Error ? err.stack : err}`); ctx.set({ 'Content-Type': 'text/html; charset=UTF-8', }); ctx.body = `RSSHub 发生了一些意外:
${err instanceof Error ? err.stack : err}`;
ctx.status = 404;
if (!ctx.debug.errorPaths[ctx.request.path]) {
ctx.debug.errorPaths[ctx.request.path] = 0;
}
ctx.debug.errorPaths[ctx.request.path]++;
if (!ctx.debug.errorRoutes[ctx._matchedRoute]) {
ctx.debug.errorRoutes[ctx._matchedRoute] = 0;
}
ctx.debug.errorRoutes[ctx._matchedRoute]++;
}
};