Skip to content

Commit

Permalink
fix(core): make sure timeout error messages include URLs (#7981)
Browse files Browse the repository at this point in the history
Before this fix, timeout messages are not quite useful

> error: Request undefined fail, retry attempt #1: TimeoutError: Timeout awaiting 'request' for 5000ms
  • Loading branch information
Chih-Hsuan Yen authored Aug 12, 2021
1 parent 47d1305 commit 1c9c4cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/got.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
6 changes: 6 additions & 0 deletions test/utils/got.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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();
});
});

1 comment on commit 1c9c4cc

@vercel
Copy link

@vercel vercel bot commented on 1c9c4cc Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.