feat: wrong path error

This commit is contained in:
DIYgod
2019-06-19 18:52:13 +08:00
parent 7c2f4777af
commit b9ab52a0d5
2 changed files with 12 additions and 0 deletions

View File

@@ -3,6 +3,10 @@ const he = require('he');
module.exports = async (ctx, next) => {
await next();
if (!ctx._matchedRoute) {
throw Error('wrong path');
}
if (ctx.state.data && (!ctx.state.data.item || ctx.state.data.item.length === 0) && !ctx.state.allowEmpty) {
throw Error('this route is empty, please check the origin site or create an issue to feedback on https://github.com/DIYgod/RSSHub/issues/new/choose');
}

View File

@@ -127,3 +127,11 @@ describe('allow_empty', () => {
expect(parsed.items.length).toBe(0);
});
});
describe('wrong_path', () => {
it(`wrong_path`, async () => {
const response = await request.get('/wrong');
expect(response.status).toBe(404);
expect(response.text).toMatch(/RSSHub 发生了一些意外: <pre>Error: wrong path/);
});
});