feat: handle HTTPError

This commit is contained in:
DIYgod
2019-09-04 14:27:38 +08:00
parent 3cebb70ef4
commit 223d426d91

View File

@@ -15,11 +15,19 @@ module.exports = async (ctx, next) => {
try {
await next();
} catch (err) {
logger.error(`Error in ${ctx.request.path}: ${err instanceof Error ? err.stack : err}`);
let message;
if (err.name && (err.name === 'HTTPError' || err.name === 'RequestError')) {
message = `${err.message}: target website might be blocking our access, you can <a href="https://docs.rsshub.app/install/">host your own RSSHub instance</a> for a better usability.`;
} else if (err instanceof Error) {
message = err.stack;
} else {
message = err;
}
logger.error(`Error in ${ctx.request.path}: ${message}`);
ctx.set({
'Content-Type': 'text/html; charset=UTF-8',
});
ctx.body = `RSSHub 发生了一些意外: <pre>${err instanceof Error ? err.stack : err}</pre>`;
ctx.body = `RSSHub 发生了一些意外: <pre>${message}</pre>`;
ctx.status = 404;
if (!ctx.debug.errorPaths[ctx.request.path]) {