Add retry logic with exponential backoff to API client#30
Add retry logic with exponential backoff to API client#30Yukaii merged 3 commits intohackmdio:developfrom
Conversation
nodejs/src/index.ts
Outdated
| "Content-Type": "application/json", | ||
| } | ||
| }, | ||
| timeout: 30000, // Increased timeout for low bandwidth |
There was a problem hiding this comment.
Could you provide as an option of APIClient options?
There was a problem hiding this comment.
APIClient options type has been expand and methods have been made options of it.
nodejs/src/index.ts
Outdated
| ) | ||
| ); | ||
| } | ||
| this.createRetryInterceptor(this.axios, 3); // Add retry interceptor with maxRetries = 3 |
There was a problem hiding this comment.
The maxRetries should also be an option
| return ( | ||
| !error.response || | ||
| (error.response.status >= 500 && error.response.status < 600) || | ||
| error.response.status === 429 |
There was a problem hiding this comment.
Could you please also check out the headers? If there are no user remaining API credits, prevent retrying.
There was a problem hiding this comment.
Added a mechanism to check API rate limits (x-ratelimit-userlimit, x-ratelimit-userremaining) and trigger retries or failures based on remaining credits.
Taombawkry
left a comment
There was a problem hiding this comment.
Comments Addressed
nodejs/src/index.ts
Outdated
| "Content-Type": "application/json", | ||
| } | ||
| }, | ||
| timeout: 30000, // Increased timeout for low bandwidth |
There was a problem hiding this comment.
APIClient options type has been expand and methods have been made options of it.
| private axios: AxiosInstance | ||
|
|
||
| constructor (readonly accessToken: string, public hackmdAPIEndpointURL: string = "https://api.hackmd.io/v1", public options: APIClientOptions = { wrapResponseErrors: true }) { | ||
| constructor ( |
There was a problem hiding this comment.
Constructor is easier to read this way
| return ( | ||
| !error.response || | ||
| (error.response.status >= 500 && error.response.status < 600) || | ||
| error.response.status === 429 |
There was a problem hiding this comment.
Added a mechanism to check API rate limits (x-ratelimit-userlimit, x-ratelimit-userremaining) and trigger retries or failures based on remaining credits.
Add retry logic with exponential backoff to API client:
#382