Skip to content

Commit 793a3b9

Browse files
committed
fix(config): retry fetching extensions on failure
1 parent d616cc3 commit 793a3b9

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/config/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"license": "MIT",
6060
"dependencies": {
6161
"@iarna/toml": "^2.2.5",
62+
"@netlify/headers-parser": "^8.0.0",
63+
"@netlify/redirect-parser": "^14.5.0",
6264
"chalk": "^5.0.0",
6365
"cron-parser": "^4.1.0",
6466
"deepmerge": "^4.2.2",
@@ -73,12 +75,11 @@
7375
"js-yaml": "^4.0.0",
7476
"map-obj": "^5.0.0",
7577
"netlify": "^13.3.3",
76-
"@netlify/headers-parser": "^8.0.0",
77-
"@netlify/redirect-parser": "^14.5.0",
7878
"node-fetch": "^3.3.1",
7979
"omit.js": "^2.0.2",
8080
"p-locate": "^6.0.0",
8181
"path-type": "^5.0.0",
82+
"retry": "^0.13.1",
8283
"tomlify-j0.4": "^3.0.0",
8384
"validate-npm-package-name": "^4.0.0",
8485
"yargs": "^17.6.0"

packages/config/src/api/site_info.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { throwUserError } from '../error.js'
77
import { ERROR_CALL_TO_ACTION } from '../log/messages.js'
88
import { IntegrationResponse } from '../types/api.js'
99
import { ModeOption, TestOptions } from '../types/options.js'
10+
import retry from "retry"
1011

1112
type GetSiteInfoOpts = {
1213
siteId: string
@@ -149,15 +150,28 @@ const getIntegrations = async function ({
149150
}
150151
}
151152

152-
const response = await fetch(url, requestOptions)
153-
if (!response.ok) {
154-
throw new Error(`Unexpected status code ${response.status} from fetching extensions`)
155-
}
156-
const bodyText = await response.text()
153+
const MAX_RETRY = 3
154+
155+
const retryOperation = retry.operation({
156+
retries: MAX_RETRY,
157+
minTimeout: 1 * 500,
158+
maxTimeout: 5 * 1000,
159+
})
160+
161+
let bodyText
162+
163+
retryOperation.attempt(async () => {
164+
const response = await fetch(url, requestOptions)
165+
if (!response.ok) {
166+
throw new Error(`Unexpected status code ${response.status} from fetching extensions`)
167+
}
168+
169+
bodyText = await response.text()
170+
})
171+
157172
if (bodyText === '') {
158173
return []
159174
}
160-
161175
const integrations = await JSON.parse(bodyText)
162176
return Array.isArray(integrations) ? integrations : []
163177
} catch (error) {

0 commit comments

Comments
 (0)