Skip to content

Commit 280eabe

Browse files
feat: implement axios retry to avoid non-reproducible 403 results
1 parent 89458c2 commit 280eabe

File tree

7 files changed

+91
-11
lines changed

7 files changed

+91
-11
lines changed

package-lock.json

Lines changed: 66 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-devops-bicep-task",
3-
"version": "0.4.3",
3+
"version": "0.4.4",
44
"description": "Tasks for installing Bicep CLI and running Bicep CLI build commands",
55
"main": "index.js",
66
"scripts": {
@@ -38,6 +38,7 @@
3838
"homepage": "https://github.com/piraces/azure-devops-bicep-task#readme",
3939
"dependencies": {
4040
"axios": "^0.27.2",
41+
"axios-retry": "^3.4.0",
4142
"azure-pipelines-task-lib": "^4.2.0",
4243
"azure-pipelines-tool-lib": "^2.0.0-preview",
4344
"glob": "^8.1.0"
@@ -49,7 +50,6 @@
4950
"@types/q": "^1.5.5",
5051
"@typescript-eslint/eslint-plugin": "^5.51.0",
5152
"@typescript-eslint/parser": "^5.51.0",
52-
5353
"eslint": "^8.34.0",
5454
"eslint-config-prettier": "^8.6.0",
5555
"eslint-plugin-prettier": "^4.2.1",

src/decompile/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"version": {
1717
"Major": 0,
1818
"Minor": 4,
19-
"Patch": 3
19+
"Patch": 4
2020
},
2121
"instanceNameFormat": "Run Bicep CLI decompile command",
2222
"inputs": [

src/install/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@ import { platform, arch } from 'os';
44
import * as taskLib from 'azure-pipelines-task-lib/task';
55
import * as toolLib from 'azure-pipelines-tool-lib/tool';
66
import { ClientRequest } from 'http';
7-
import axios from 'axios';
7+
import axios, { AxiosError } from 'axios';
8+
import axiosRetry from 'axios-retry';
9+
10+
axiosRetry(axios,
11+
{
12+
retries: 3,
13+
retryCondition: (error: AxiosError) => {
14+
if (!error.response || error.response.status >= 400) {
15+
if (error.response) {
16+
taskLib.debug(`Retrying request with status code '${error.response.status}'.`);
17+
taskLib.debug(`Response received: '${JSON.stringify(error.response)}'.`);
18+
}
19+
return true;
20+
}
21+
return false;
22+
}
23+
});
824

925
export function getDownloadUrl(version: string): string {
1026
const agentPlatform = platform();
@@ -53,11 +69,11 @@ export async function getLatestVersionTag(): Promise<string> {
5369
// The request was made and the server responded with a status code
5470
// that falls out of the range of 2xx
5571
throw new Error(
56-
`[FATAL] Error while retrieving latest version tag: '${error.message}'.\nResponse: \n-Data: '${error.response.data}' \n-Status: '${error.response.status}' \n-Headers: '${error.response.headers}'`,
72+
`[FATAL] Error while retrieving latest version tag: '${error.message}'.\nResponse: \n-Data: '${JSON.stringify(error.response.data)}' \n-Status: '${error.response.status}' \n-Headers: '${JSON.stringify(error.response.headers)}'`,
5773
);
5874
} else if (error.request) {
5975
throw new Error(
60-
`[FATAL] Error while retrieving latest version tag: '${error.message}'.\nRequest: '${error.request}'\nConfig: '${error.config}'`,
76+
`[FATAL] Error while retrieving latest version tag: '${error.message}'.\nRequest: '${JSON.stringify(error.request)}'\nConfig: '${error.config}'`,
6177
);
6278
} else {
6379
throw new Error(

src/install/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"version": {
1717
"Major": 0,
1818
"Minor": 4,
19-
"Patch": 3
19+
"Patch": 4
2020
},
2121
"instanceNameFormat": "Install Bicep CLI",
2222
"inputs": [

src/run/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"version": {
1717
"Major": 0,
1818
"Minor": 4,
19-
"Patch": 3
19+
"Patch": 4
2020
},
2121
"instanceNameFormat": "Run Bicep CLI build command",
2222
"inputs": [

vss-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifestVersion": 1,
33
"id": "bicep-tasks",
4-
"version": "0.4.3",
4+
"version": "0.4.4",
55
"name": "Bicep Tasks",
66
"publisher": "piraces",
77
"description": "Provides Azure DevOps tasks to install and run Microsoft Bicep CLI commands (cross-platform)",

0 commit comments

Comments
 (0)