Skip to content

Commit

Permalink
feat: handle HTTPError
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Sep 4, 2019
1 parent 3cebb70 commit 223d426
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/middleware/onerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit 223d426

Please sign in to comment.