diff --git a/lib/middleware/access-control.js b/lib/middleware/access-control.js index bdb1be26f..81459d863 100644 --- a/lib/middleware/access-control.js +++ b/lib/middleware/access-control.js @@ -5,7 +5,7 @@ const isLocalhost = require('is-localhost-ip'); const reject = (ctx) => { ctx.response.status = 403; - throw Error('Access denied.'); + throw Error('Authentication failed. Access denied.'); }; module.exports = async (ctx, next) => { diff --git a/lib/middleware/onerror.js b/lib/middleware/onerror.js index ff80f5837..bbdb19cdd 100644 --- a/lib/middleware/onerror.js +++ b/lib/middleware/onerror.js @@ -91,7 +91,7 @@ Please ensure you have deployed the [master branch](https://github.com/DIYgod/RS templateEn )}" target="_blank">report me on GitHub.`; } else if (err instanceof Error) { - message = err.stack; + message = process.env.NODE_ENV === 'production' ? err.message : err.stack; } logger.error(`Error in ${ctx.request.path}: ${message}`); @@ -105,12 +105,18 @@ Please ensure you have deployed the [master branch](https://github.com/DIYgod/RS ctx.set({ 'Content-Type': 'text/html; charset=UTF-8', }); - ctx.body = art(path.resolve(__dirname, '../views/error.art'), { - message, - }); - if (ctx.status !== 403) { + if (ctx.status === 403) { + message = err.message; + } else { ctx.status = 404; } + + const requestPath = ctx.request.path; + + ctx.body = art(path.resolve(__dirname, '../views/error.art'), { + requestPath, + message, + }); } if (!ctx.debug.errorPaths[ctx.request.path]) { diff --git a/lib/views/error.art b/lib/views/error.art index 187fc0498..831d7f35b 100644 --- a/lib/views/error.art +++ b/lib/views/error.art @@ -37,10 +37,14 @@

Looks like something went wrong

-
{{@ message }}
+
Route requested: {{@ requestPath }}
+
Error message: {{@ message }}
-

For online documentation and support please refer to - docs.rsshub.app.

+
+

在线文档与支持,请访问docs.rsshub.app

+

For online documentation and support please refer to + docs.rsshub.app.

+