mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 07:12:51 +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: {
|
||||
beforeRetry: [
|
||||
(options, err, count) => {
|
||||
logger.error(`Request ${err.url} fail, retry attempt #${count}: ${err}`);
|
||||
logger.error(`Request ${options.url} fail, retry attempt #${count}: ${err}`);
|
||||
},
|
||||
],
|
||||
afterResponse: [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
process.env.REQUEST_TIMEOUT = '500';
|
||||
const got = require('../../lib/utils/got');
|
||||
const logger = require('../../lib/utils/logger');
|
||||
const config = require('../../lib/config').value;
|
||||
const nock = require('nock');
|
||||
|
||||
@@ -65,11 +66,16 @@ describe('got', () => {
|
||||
return [200, '{"code": 0}'];
|
||||
});
|
||||
|
||||
const loggerSpy = jest.spyOn(logger, 'error').mockReturnValue({});
|
||||
|
||||
try {
|
||||
await got.get('http://rsshub.test/timeout');
|
||||
throw Error('Timeout Invalid');
|
||||
} catch (error) {
|
||||
expect(error.name).toBe('RequestError');
|
||||
}
|
||||
expect(loggerSpy).toHaveBeenCalledWith(expect.stringContaining('http://rsshub.test/timeout'));
|
||||
|
||||
loggerSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user