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:
Chih-Hsuan Yen
2021-08-12 01:27:07 -07:00
committed by GitHub
parent 47d1305f95
commit 1c9c4ccfc8
2 changed files with 7 additions and 1 deletions
+6
View File
@@ -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();
});
});