mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 20:27:52 +08:00
feat: handle HTTPError
This commit is contained in:
@@ -15,11 +15,19 @@ module.exports = async (ctx, next) => {
|
|||||||
try {
|
try {
|
||||||
await next();
|
await next();
|
||||||
} catch (err) {
|
} 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({
|
ctx.set({
|
||||||
'Content-Type': 'text/html; charset=UTF-8',
|
'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;
|
ctx.status = 404;
|
||||||
|
|
||||||
if (!ctx.debug.errorPaths[ctx.request.path]) {
|
if (!ctx.debug.errorPaths[ctx.request.path]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user