Skip to content

Commit

Permalink
Fix code feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Oct 15, 2024
1 parent 5ff5534 commit 45ecb57
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions packages/api/src/utils/client/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ export class HttpClient implements IHttpClient {
this.logger?.debug("Requesting fallback URL", {routeId, baseUrl: printableUrl, score: this.urlsScore[i]});
}

const localIndex = i; // Keep local copy of i variable to index urlScore after requestWithBody() resolves
// biome-ignore lint/style/useNamingConvention: Author preferred this format
const i_ = i; // Keep local copy of i variable to index urlScore after requestWithBody() resolves

const urlInit = this.urlsInits[i];
if (urlInit === undefined) {
Expand All @@ -209,17 +210,11 @@ export class HttpClient implements IHttpClient {
requestMethod(definition, args, init).then(
async (res) => {
if (res.ok) {
this.urlsScore[localIndex] = Math.min(
URL_SCORE_MAX,
this.urlsScore[localIndex] + URL_SCORE_DELTA_SUCCESS
);
this.urlsScore[i_] = Math.min(URL_SCORE_MAX, this.urlsScore[i_] + URL_SCORE_DELTA_SUCCESS);
// Resolve immediately on success
resolve(res);
} else {
this.urlsScore[localIndex] = Math.max(
URL_SCORE_MIN,
this.urlsScore[localIndex] - URL_SCORE_DELTA_ERROR
);
this.urlsScore[i_] = Math.max(URL_SCORE_MIN, this.urlsScore[i_] - URL_SCORE_DELTA_ERROR);

// Resolve failed response only when all queried URLs have errored
if (++errorCount >= requestCount) {
Expand All @@ -234,10 +229,7 @@ export class HttpClient implements IHttpClient {
}
},
(err) => {
this.urlsScore[localIndex] = Math.max(
URL_SCORE_MIN,
this.urlsScore[localIndex] - URL_SCORE_DELTA_ERROR
);
this.urlsScore[i_] = Math.max(URL_SCORE_MIN, this.urlsScore[i_] - URL_SCORE_DELTA_ERROR);

// Reject only when all queried URLs have errored
// TODO: Currently rejects with last error only, should join errors?
Expand Down

0 comments on commit 45ecb57

Please sign in to comment.