Skip to content

Commit

Permalink
Re-introduce loop
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Aug 12, 2024
1 parent e97839d commit 8ac4717
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions dev-packages/ovsx-client/src/ovsx-http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,22 @@ export class OVSXHttpClient implements OVSXClient {
}

protected async requestJson<R>(url: string): Promise<R> {
await this.rateLimiter.removeTokens(1);
const context = await this.requestService.request({
url,
headers: { 'Accept': 'application/json' }
});
if (context.res.statusCode === 429) {
console.warn('OVSX rate limit exceeded. Consider reducing the rate limit.');
const attempts = 5;
for (let i = 0; i < attempts; i++) {
await this.rateLimiter.removeTokens(i + 1);
const context = await this.requestService.request({
url,
headers: { 'Accept': 'application/json' }
});
if (context.res.statusCode === 429) {
console.warn('OVSX rate limit exceeded. Will perform request with higher timeout. Consider reducing the rate limit.');
if (i < attempts - 1) {
continue;
}
}
return RequestContext.asJson<R>(context);
}
return RequestContext.asJson<R>(context);
throw new Error('Request timed out due to too many requests');
}

protected buildUrl(url: string, query?: object): string {
Expand Down

0 comments on commit 8ac4717

Please sign in to comment.