-
-
Looks like something went wrong
- - - - - - -For online documentation and support please refer to - docs.rsshub.app.
-在线文档与支持,请访问 docs.rsshub.app。
-diff --git a/lib/errors/index.test.ts b/lib/errors/index.test.ts
index b493ab740..a89a84af6 100644
--- a/lib/errors/index.test.ts
+++ b/lib/errors/index.test.ts
@@ -13,7 +13,7 @@ afterAll(() => {
describe('error', () => {
it(`error`, async () => {
const response = await request.get('/test/error');
- expect(response.status).toBe(404);
+ expect(response.status).toBe(503);
expect(response.text).toMatch(/Error: Error test/);
});
});
@@ -21,10 +21,8 @@ describe('error', () => {
describe('httperror', () => {
it(`httperror`, async () => {
const response = await request.get('/test/httperror');
- expect(response.status).toBe(404);
- expect(response.text).toMatch(
- /Response code 404 \(Not Found\): target website might be blocking our access, you can host your own RSSHub instance<\/a> for a better usability\./
- );
+ expect(response.status).toBe(503);
+ expect(response.text).toMatch('Response code 404 (Not Found): target website might be blocking our access, you can host your own RSSHub instance for a better usability.');
}, 20000);
});
diff --git a/lib/errors/index.ts b/lib/errors/index.tsx
similarity index 53%
rename from lib/errors/index.ts
rename to lib/errors/index.tsx
index dd69b50ff..f2ff4bde7 100644
--- a/lib/errors/index.ts
+++ b/lib/errors/index.tsx
@@ -3,27 +3,16 @@ import { getDebugInfo, setDebugInfo } from '@/utils/debug-info';
import { config } from '@/config';
import Sentry from '@sentry/node';
import logger from '@/utils/logger';
-import art from 'art-template';
-import * as path from 'node:path';
-import { gitHash } from '@/utils/git-hash';
+import Error from '@/views/error';
import RequestInProgressError from './request-in-progress';
import RejectError from './reject';
import NotFoundError from './not-found';
-import { getCurrentPath } from '@/utils/helpers';
-const __dirname = getCurrentPath(import.meta.url);
-
export const errorHandler: ErrorHandler = (error, ctx) => {
const requestPath = ctx.req.path;
const matchedRoute = ctx.req.routePath;
const hasMatchedRoute = matchedRoute !== '/*';
- let message = '';
- if (error.name && (error.name === 'HTTPError' || error.name === 'RequestError')) {
- message = `${error.message}: target website might be blocking our access, you can host your own RSSHub instance for a better usability.`;
- } else if (error instanceof Error) {
- message = process.env.NODE_ENV === 'production' ? error.message : error.stack || error.message;
- }
const debug = getDebugInfo();
if (ctx.res.headers.get('RSSHub-Cache-Status')) {
@@ -49,42 +38,42 @@ export const errorHandler: ErrorHandler = (error, ctx) => {
});
}
+ let message = '';
+ if (error.name && (error.name === 'HTTPError' || error.name === 'RequestError')) {
+ ctx.status(503);
+ message = `${error.message}: target website might be blocking our access, you can host your own RSSHub instance for a better usability.`;
+ } else if (error instanceof RequestInProgressError) {
+ ctx.header('Cache-Control', `public, max-age=${config.requestTimeout / 1000}`);
+ ctx.status(503);
+ message = error.message;
+ } else if (error instanceof RejectError) {
+ ctx.status(403);
+ message = error.message;
+ } else if (error instanceof NotFoundError) {
+ ctx.status(404);
+ message = 'wrong path';
+ if (ctx.req.path.endsWith('/')) {
+ message += ', you can try removing the trailing slash in the path';
+ }
+ } else {
+ ctx.status(503);
+ message = process.env.NODE_ENV === 'production' ? error.message : error.stack || error.message;
+ }
+
logger.error(`Error in ${requestPath}: ${message}`);
- if (config.isPackage) {
- return ctx.json({
- error: {
- message: error.message ?? error,
- },
- });
- } else {
- if (error instanceof RequestInProgressError) {
- ctx.header('Cache-Control', `public, max-age=${config.requestTimeout / 1000}`);
- ctx.status(503);
- message = error.message;
- } else if (error instanceof RejectError) {
- ctx.status(403);
- message = error.message;
- } else if (error instanceof NotFoundError) {
- ctx.status(404);
- message = 'wrong path';
- if (ctx.req.path.endsWith('/')) {
- message += ', you can try removing the trailing slash in the path';
- }
- } else {
- ctx.status(404);
- }
-
- return ctx.html(
- art(path.resolve(__dirname, '../views/error.art'), {
- requestPath,
- message,
- errorRoute: hasMatchedRoute ? matchedRoute : requestPath,
- nodeVersion: process.version,
- gitHash,
- })
- );
- }
+ return config.isPackage ? ctx.json({
+ error: {
+ message: error.message ?? error,
+ },
+ }) : ctx.html((
+
-
-
For online documentation and support please refer to - docs.rsshub.app.
-在线文档与支持,请访问 docs.rsshub.app。
-
+ Helpful Information
+Error Message:
+{message}
+ Route: {errorRoute}
Full Route: {requestPath}
Node Version: {nodeVersion}
Git Hash: {gitHash}
Git Date: {gitDate?.toUTCString()}
Report
+After carefully reading the document, if you think this is a bug of RSSHub, please submit an issue on GitHub.
+ +Community
+You can also join our Telegram group, or follow our Telegram channel and Twitter to get community support and news.
+你也可以加入我们的 Telegram 群组,或关注我们的 Telegram 频道和 Twitter 获取社区支持和新闻。
++ Please consider{' '} + + sponsoring + {' '} + to help keep this open source project alive. +
++ Made with ❤️ by{' '} + + DIYgod + {' '} + and{' '} + + Contributors + {' '} + under MIT License. +
+