mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
fix: not found error handler
This commit is contained in:
+2
-1
@@ -13,7 +13,7 @@ import parameter from '@/middleware/parameter';
|
||||
import logger from '@/utils/logger';
|
||||
|
||||
import routes from '@/routes';
|
||||
import { errorHandler } from '@/errors';
|
||||
import { notFoundHandler, errorHandler } from '@/errors';
|
||||
|
||||
process.on('uncaughtException', (e) => {
|
||||
logger.error('uncaughtException: ' + e);
|
||||
@@ -32,6 +32,7 @@ app.use('*', cache);
|
||||
|
||||
routes(app);
|
||||
|
||||
app.notFound(notFoundHandler);
|
||||
app.onError(errorHandler);
|
||||
|
||||
export default app;
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ export type Config = {
|
||||
model?: string;
|
||||
temperature?: number;
|
||||
maxTokens?: number;
|
||||
endpoint?: string;
|
||||
endpoint: string;
|
||||
prompt?: string;
|
||||
};
|
||||
bilibili: {
|
||||
|
||||
+7
-1
@@ -1,4 +1,4 @@
|
||||
import { type ErrorHandler } from 'hono';
|
||||
import { type NotFoundHandler, type ErrorHandler } from 'hono';
|
||||
import { getDebugInfo, setDebugInfo } from '@/utils/debug-info';
|
||||
import { config } from '@/config';
|
||||
import Sentry from '@sentry/node';
|
||||
@@ -9,6 +9,7 @@ import gitHash from '@/utils/git-hash';
|
||||
|
||||
import RequestInProgressError from './request-in-progress';
|
||||
import RejectError from './reject';
|
||||
import NotFoundError from './not-found';
|
||||
|
||||
export const errorHandler: ErrorHandler = (error, ctx) => {
|
||||
let message = '';
|
||||
@@ -49,6 +50,9 @@ export const errorHandler: ErrorHandler = (error, ctx) => {
|
||||
} else if (error instanceof RejectError) {
|
||||
ctx.status(403);
|
||||
message = error.message;
|
||||
} else if (error instanceof NotFoundError) {
|
||||
ctx.status(404);
|
||||
message = 'wrong path';
|
||||
} else {
|
||||
ctx.status(404);
|
||||
}
|
||||
@@ -66,3 +70,5 @@ export const errorHandler: ErrorHandler = (error, ctx) => {
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const notFoundHandler: NotFoundHandler = (ctx) => errorHandler(new NotFoundError(), ctx);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class NotFoundError extends Error {}
|
||||
|
||||
export default NotFoundError;
|
||||
Reference in New Issue
Block a user