adobe / adobe/node-fetch-retry

allow customizing of retry logging handler

Open
#77 0 comments 4 reactions 1 assignee Claimed by @alexkli View on GitHub
enhancement
Dominant language
JavaScript
Stars
44
Forks
16
PR merge metrics
No merged PRs in 30d

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](https://github.com/adobe/node-fetch-retry/blob/master/index.js#L221).

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).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.