mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
feat: error page
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
const logger = require('@/utils/logger');
|
const logger = require('@/utils/logger');
|
||||||
const config = require('@/config');
|
const config = require('@/config');
|
||||||
const Sentry = require('@sentry/node');
|
const Sentry = require('@sentry/node');
|
||||||
|
const art = require('art-template');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
if (config.sentry) {
|
if (config.sentry) {
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
@@ -25,7 +27,9 @@ module.exports = async (ctx, next) => {
|
|||||||
ctx.set({
|
ctx.set({
|
||||||
'Content-Type': 'text/html; charset=UTF-8',
|
'Content-Type': 'text/html; charset=UTF-8',
|
||||||
});
|
});
|
||||||
ctx.body = `Looks like something went wrong in RSSHub: <pre>${message}</pre>`;
|
ctx.body = art(path.resolve(__dirname, '../views/error.art'), {
|
||||||
|
message,
|
||||||
|
});
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
|
|
||||||
if (!ctx.debug.errorPaths[ctx.request.path]) {
|
if (!ctx.debug.errorPaths[ctx.request.path]) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ module.exports = async (ctx, next) => {
|
|||||||
|
|
||||||
if (ctx.state.data) {
|
if (ctx.state.data) {
|
||||||
if ((!ctx.state.data.item || ctx.state.data.item.length === 0) && !ctx.state.data.allowEmpty) {
|
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 <a href="https://github.com/DIYgod/RSSHub/issues/new/choose">create an issue</a>');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.query && ctx.query.mode && ctx.query.mode.toLowerCase() === 'fulltext') {
|
if (ctx.query && ctx.query.mode && ctx.query.mode.toLowerCase() === 'fulltext') {
|
||||||
|
|||||||
47
lib/views/error.art
Normal file
47
lib/views/error.art
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Error in RSSHub!</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
font-size: 16px;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
width: 800px;
|
||||||
|
margin: 100px auto 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #F5712C;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="content">
|
||||||
|
<p>
|
||||||
|
<img src="https://i.loli.net/2019/09/04/lmBbNQoLzrKGgiM.jpg" alt="RSSHub" width="120">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h1>Looks like something went wrong</h1>
|
||||||
|
|
||||||
|
<pre class="message">{{@ message }}</pre>
|
||||||
|
|
||||||
|
<p style="margin: 50px 0">For online documentation and support please refer to
|
||||||
|
<a href="https://docs.rsshub.app/" target="_blank">docs.rsshub.app</a>.</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
<title>Welcome to RSSHub!</title>
|
<title>Welcome to RSSHub!</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
width: 35em;
|
|
||||||
margin: 0 auto;
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
@@ -16,13 +14,16 @@
|
|||||||
|
|
||||||
.content {
|
.content {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 40%;
|
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, 100px);
|
||||||
min-width: 400px;
|
min-width: 400px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #F5712C;
|
||||||
|
}
|
||||||
|
|
||||||
details {
|
details {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
max-height: 400px;
|
max-height: 400px;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ describe('error', () => {
|
|||||||
it(`error`, async () => {
|
it(`error`, async () => {
|
||||||
const response = await request.get('/test/error');
|
const response = await request.get('/test/error');
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
expect(response.text).toMatch(/Looks like something went wrong in RSSHub: <pre>Error: Error test/);
|
expect(response.text).toMatch(/Error: Error test/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ describe('httperror', () => {
|
|||||||
const response = await request.get('/test/httperror');
|
const response = await request.get('/test/httperror');
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
expect(response.text).toMatch(
|
expect(response.text).toMatch(
|
||||||
/Looks like something went wrong in RSSHub: <pre>Response code 404 \(Not Found\): 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\./
|
/Response code 404 \(Not Found\): 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\./
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ describe('empty', () => {
|
|||||||
it(`empty`, async () => {
|
it(`empty`, async () => {
|
||||||
const response1 = await request.get('/test/empty');
|
const response1 = await request.get('/test/empty');
|
||||||
expect(response1.status).toBe(404);
|
expect(response1.status).toBe(404);
|
||||||
expect(response1.text).toMatch(/Looks like something went wrong in RSSHub: <pre>Error: this route is empty/);
|
expect(response1.text).toMatch(/Error: this route is empty/);
|
||||||
|
|
||||||
const response2 = await request.get('/test/1?limit=0');
|
const response2 = await request.get('/test/1?limit=0');
|
||||||
expect(response2.status).toBe(200);
|
expect(response2.status).toBe(200);
|
||||||
@@ -132,7 +132,7 @@ describe('wrong_path', () => {
|
|||||||
it(`wrong_path`, async () => {
|
it(`wrong_path`, async () => {
|
||||||
const response = await request.get('/wrong');
|
const response = await request.get('/wrong');
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
expect(response.text).toMatch(/Looks like something went wrong in RSSHub: <pre>Error: wrong path/);
|
expect(response.text).toMatch(/Error: wrong path/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ describe('template', () => {
|
|||||||
it(`.json`, async () => {
|
it(`.json`, async () => {
|
||||||
const response = await request.get('/test/1.json');
|
const response = await request.get('/test/1.json');
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
expect(response.text).toMatch(/Looks like something went wrong in RSSHub: <pre>Error: <b>JSON output had been removed/);
|
expect(response.text).toMatch(/Error: <b>JSON output had been removed/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`long title`, async () => {
|
it(`long title`, async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user