Skip to content

Commit

Permalink
chore: Upgrade Axios to 1.7.7 and catch Axios post errors in async ca…
Browse files Browse the repository at this point in the history
…ll (#1254)
  • Loading branch information
jorenn92 authored Sep 6, 2024
1 parent 8227f8c commit c392d13
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@nestjs/schedule": "^4.0.0",
"@nestjs/typeorm": "^10.0.2",
"@types/node": "^22.2.0",
"axios": "^1.7.4",
"axios": "^1.7.7",
"bowser": "^2.11.0",
"chalk": "^4.1.2",
"cron": "3.1.3",
Expand Down
22 changes: 12 additions & 10 deletions server/src/modules/api/external-api/external-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,16 @@ export class ExternalApiService {
const response = await this.axios
.post<T>(endpoint, data, config)
.catch((err: AxiosError) => {
throw err;
if (err.response?.status === 429) {
const retryAfter = err.response.headers['retry-after'] || 'unknown';
Logger.warn(
`${endpoint} Rate limit hit. Retry after: ${retryAfter} seconds.`,
);
} else {
Logger.warn(`POST request to ${endpoint} failed: ${err.message}`);
Logger.debug(err);
}
return undefined;
});

if (this.cache) {
Expand All @@ -189,15 +198,8 @@ export class ExternalApiService {

return response.data;
} catch (err: any) {
if (err.response?.status === 429) {
const retryAfter = err.response.headers['retry-after'] || 'unknown';
Logger.warn(
`${endpoint} Rate limit hit. Retry after: ${retryAfter} seconds.`,
);
} else {
Logger.warn(`POST request failed: ${err.message}`);
Logger.debug(err);
}
Logger.warn(`POST request to ${endpoint} failed: ${err.message}`);
Logger.debug(err);
return undefined;
}
}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5450,14 +5450,14 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.7.4":
version: 1.7.4
resolution: "axios@npm:1.7.4"
"axios@npm:^1.7.7":
version: 1.7.7
resolution: "axios@npm:1.7.7"
dependencies:
follow-redirects: "npm:^1.15.6"
form-data: "npm:^4.0.0"
proxy-from-env: "npm:^1.1.0"
checksum: 10c0/5ea1a93140ca1d49db25ef8e1bd8cfc59da6f9220159a944168860ad15a2743ea21c5df2967795acb15cbe81362f5b157fdebbea39d53117ca27658bab9f7f17
checksum: 10c0/4499efc89e86b0b49ffddc018798de05fab26e3bf57913818266be73279a6418c3ce8f9e934c7d2d707ab8c095e837fc6c90608fb7715b94d357720b5f568af7
languageName: node
linkType: hard

Expand Down Expand Up @@ -11158,7 +11158,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": "npm:^8.3.0"
"@typescript-eslint/parser": "npm:^7.16.0"
autoprefixer: "npm:10.4.20"
axios: "npm:^1.7.4"
axios: "npm:^1.7.7"
bowser: "npm:^2.11.0"
chalk: "npm:^4.1.2"
cron: "npm:3.1.3"
Expand Down

0 comments on commit c392d13

Please sign in to comment.