Skip to content

Commit

Permalink
chore(live-network): only retry network for status code that makes se…
Browse files Browse the repository at this point in the history
…nse (#7334)
  • Loading branch information
gre authored Jul 16, 2024
1 parent ad9594b commit 53ff78c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-windows-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-network": minor
---

live-network no longer retry network calls on HTTP status code that shouldn't be retried like 401 & some others.
9 changes: 6 additions & 3 deletions libs/live-network/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ export type LiveNetworkResponse<T> = {
data: T;
status: number;
};

// inspired by https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#retry
const retryableHttpStatusCodes = [408, 413, 429, 500, 502, 503, 504, 521, 522, 524];

/**
* Network call
* @param request
Expand All @@ -198,9 +202,8 @@ export const newImplementation = async <T = unknown, U = unknown>(
maxRetry: getEnv("GET_CALLS_RETRY"),
retryCondition: error => {
if (error && error.status) {
// A 422 shouldn't be retried without change as explained in this documentation
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422
return error.status !== 422;
// not all status codes are retryable
return retryableHttpStatusCodes.includes(error.status);
}
return true;
},
Expand Down

0 comments on commit 53ff78c

Please sign in to comment.