-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Current Behaviour
Currently node-fetch-retry
will console.log
or console.error
on retry (and other cases), with a specific message. For example here.
Inventory of console.*
:
on retry:
- https://github.com/adobe/node-fetch-retry/blob/master/index.js#L158 (shouldRetryOnHttpError a)
- https://github.com/adobe/node-fetch-retry/blob/master/index.js#L161 (shouldRetryOnHttpError b)
- https://github.com/adobe/node-fetch-retry/blob/master/index.js#L221 (on http response not ok)
- https://github.com/adobe/node-fetch-retry/blob/master/index.js#L235 (on error thrown)
on init (config read):
- https://github.com/adobe/node-fetch-retry/blob/master/index.js#L90 (on forceSocketTimeout)
Issue
Apps using node-fetch-try
might want a different log message or use a different logging.
For example, they might want to log error details from a specific header or the response body. Currently it only prints the response.statusText
in case of a non-success HTTP response.
Apps should be in control and be able to have node-fetch-retry
not call console.*
at all.
Proposal
Add the option for a custom function onRetry
in the retryOptions
that would be used instead of the current logging. Signature might follow the usual pattern
function onRetry(response, error) {
// response if response was returned otherwise null
// error if an error was thrown
}
Note sure how to handle the "on init" case, maybe another onInitLog
function. Or use the npm debug
library (which is off by default).