From 24cab914d89bbceeb742d7fe988af9904791a08e Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 4 Sep 2019 16:00:00 +0800 Subject: [PATCH] feat: error page --- lib/middleware/onerror.js | 6 ++++- lib/middleware/parameter.js | 2 +- lib/views/error.art | 47 ++++++++++++++++++++++++++++++++++++ lib/views/welcome.art | 9 ++++--- test/middleware/onerror.js | 4 +-- test/middleware/parameter.js | 4 +-- test/middleware/template.js | 2 +- 7 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 lib/views/error.art diff --git a/lib/middleware/onerror.js b/lib/middleware/onerror.js index 6981be7754..1bb5ae8476 100644 --- a/lib/middleware/onerror.js +++ b/lib/middleware/onerror.js @@ -1,6 +1,8 @@ const logger = require('@/utils/logger'); const config = require('@/config'); const Sentry = require('@sentry/node'); +const art = require('art-template'); +const path = require('path'); if (config.sentry) { Sentry.init({ @@ -25,7 +27,9 @@ module.exports = async (ctx, next) => { ctx.set({ 'Content-Type': 'text/html; charset=UTF-8', }); - ctx.body = `Looks like something went wrong in RSSHub:
${message}
`; + ctx.body = art(path.resolve(__dirname, '../views/error.art'), { + message, + }); ctx.status = 404; if (!ctx.debug.errorPaths[ctx.request.path]) { diff --git a/lib/middleware/parameter.js b/lib/middleware/parameter.js index 3a2117a936..bf39b7010c 100644 --- a/lib/middleware/parameter.js +++ b/lib/middleware/parameter.js @@ -12,7 +12,7 @@ module.exports = async (ctx, next) => { if (ctx.state.data) { if ((!ctx.state.data.item || ctx.state.data.item.length === 0) && !ctx.state.data.allowEmpty) { - throw Error('this route is empty, please check the original site or create an issue on https://github.com/DIYgod/RSSHub/issues/new/choose'); + throw Error('this route is empty, please check the original site or create an issue'); } if (ctx.query && ctx.query.mode && ctx.query.mode.toLowerCase() === 'fulltext') { diff --git a/lib/views/error.art b/lib/views/error.art new file mode 100644 index 0000000000..187fc0498f --- /dev/null +++ b/lib/views/error.art @@ -0,0 +1,47 @@ + + + + + Error in RSSHub! + + + + +
+

+ RSSHub +

+ +

Looks like something went wrong

+ +
{{@ message }}
+ +

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

+
+ + + diff --git a/lib/views/welcome.art b/lib/views/welcome.art index 13a9563ae5..c4197b6380 100644 --- a/lib/views/welcome.art +++ b/lib/views/welcome.art @@ -5,8 +5,6 @@ Welcome to RSSHub!