Skip to content

handle developer errors from callbacks separate from fetch errors #87

@alexkli

Description

@alexkli

Currently we share the same catch clause for fetch() and for the shouldRetry() here:

node-fetch-retry/index.js

Lines 217 to 227 in 3e512e5

try {
const response = await fetch(url, options);
if (await shouldRetry(retryOptions, null, response, waitTime)) {
console.error(`Retrying in ${waitTime} milliseconds, attempt ${attempt} failed (status ${response.status}): ${response.statusText}`);
} else {
// response.timeout should reflect the actual timeout
response.timeout = retryOptions.socketTimeout;
return resolve(response);
}
} catch (error) {

shouldRetry includes calling the callbacks retryOnHttpError() and retryOnHttpResponse(). These callbacks could have developer errors on which we should not retry blindly.

Instead, we should separate the error handling, and for errors on the callbacks pass them through as clear errors (and do not retry) so the developers can fix their code.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions