fix(core): v2 route path should keep mounted in stats if error throws (#13965)
This commit is contained in:
parent
5921d8aba8
commit
7dee6a82d4
|
|
@ -39,6 +39,10 @@ module.exports = async (ctx, next) => {
|
|||
});
|
||||
}
|
||||
} catch (err) {
|
||||
// Append v2 route path
|
||||
ctx.request.path = (ctx.mountPath ?? '') + ctx.request.path;
|
||||
ctx._matchedRoute = ctx._matchedRoute ? (ctx.mountPath ?? '') + ctx._matchedRoute : ctx.request.path;
|
||||
|
||||
let message = err;
|
||||
if (err.name && (err.name === 'HTTPError' || err.name === 'RequestError')) {
|
||||
message = `${err.message}: 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.`;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ jest.mock('request-promise-native');
|
|||
const server = require('../../lib/index');
|
||||
const config = require('../../lib/config').value;
|
||||
const request = supertest(server);
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
|
|
@ -42,3 +43,34 @@ describe('RequestInProgressError', () => {
|
|||
expect(responses.filter((r) => r.text.includes('This path is currently fetching, please come back later!'))).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('v2 route throws an error', () => {
|
||||
it('v2 route path error should have path mounted', async () => {
|
||||
await request.get('/test/error');
|
||||
await request.get('/thisDoesNotExist');
|
||||
const response = await request.get('/');
|
||||
|
||||
const $ = cheerio.load(response.text);
|
||||
$('.debug-item').each((index, item) => {
|
||||
const key = $(item).find('.debug-key').text().trim();
|
||||
const value = $(item).find('.debug-value').html().trim();
|
||||
switch (key) {
|
||||
case 'Request Amount:':
|
||||
expect(value).toBe('7');
|
||||
break;
|
||||
case 'Hot Routes:':
|
||||
expect(value).toBe('4 /test/:id<br>1 /test/slow<br>1 /thisDoesNotExist<br>');
|
||||
break;
|
||||
case 'Hot Paths:':
|
||||
expect(value).toBe('2 /test/error<br>2 /test/slow<br>1 /test/httperror<br>1 /thisDoesNotExist<br>1 /<br>');
|
||||
break;
|
||||
case 'Hot Error Routes:':
|
||||
expect(value).toBe('3 /test/:id<br>1 /test/slow<br>1 /thisDoesNotExist<br>');
|
||||
break;
|
||||
case 'Hot Error Paths:':
|
||||
expect(value).toBe('2 /test/error<br>1 /test/httperror<br>1 /test/slow<br>1 /thisDoesNotExist<br>');
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue