mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
fix(core): make sure timeout error messages include URLs (#7981)
Before this fix, timeout messages are not quite useful > error: Request undefined fail, retry attempt #1: TimeoutError: Timeout awaiting 'request' for 5000ms
This commit is contained in:
@@ -7,7 +7,7 @@ const custom = got.extend({
|
|||||||
hooks: {
|
hooks: {
|
||||||
beforeRetry: [
|
beforeRetry: [
|
||||||
(options, err, count) => {
|
(options, err, count) => {
|
||||||
logger.error(`Request ${err.url} fail, retry attempt #${count}: ${err}`);
|
logger.error(`Request ${options.url} fail, retry attempt #${count}: ${err}`);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
afterResponse: [
|
afterResponse: [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
process.env.REQUEST_TIMEOUT = '500';
|
process.env.REQUEST_TIMEOUT = '500';
|
||||||
const got = require('../../lib/utils/got');
|
const got = require('../../lib/utils/got');
|
||||||
|
const logger = require('../../lib/utils/logger');
|
||||||
const config = require('../../lib/config').value;
|
const config = require('../../lib/config').value;
|
||||||
const nock = require('nock');
|
const nock = require('nock');
|
||||||
|
|
||||||
@@ -65,11 +66,16 @@ describe('got', () => {
|
|||||||
return [200, '{"code": 0}'];
|
return [200, '{"code": 0}'];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const loggerSpy = jest.spyOn(logger, 'error').mockReturnValue({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await got.get('http://rsshub.test/timeout');
|
await got.get('http://rsshub.test/timeout');
|
||||||
throw Error('Timeout Invalid');
|
throw Error('Timeout Invalid');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(error.name).toBe('RequestError');
|
expect(error.name).toBe('RequestError');
|
||||||
}
|
}
|
||||||
|
expect(loggerSpy).toHaveBeenCalledWith(expect.stringContaining('http://rsshub.test/timeout'));
|
||||||
|
|
||||||
|
loggerSpy.mockRestore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user