braid-http 1.3.74 → 1.3.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/braid-http-client.js +21 -13
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -132,6 +132,8 @@ if (is_nodejs) {
|
|
|
132
132
|
// window.fetch = braid_fetch
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
braid_fetch.set_fetch = f => normal_fetch = f
|
|
136
|
+
|
|
135
137
|
async function braid_fetch (url, params = {}) {
|
|
136
138
|
params = deep_copy(params) // Copy params, because we'll mutate it
|
|
137
139
|
|
|
@@ -435,21 +437,27 @@ async function braid_fetch (url, params = {}) {
|
|
|
435
437
|
}
|
|
436
438
|
}
|
|
437
439
|
|
|
438
|
-
if (params.retry) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
440
|
+
if (params.retry && !res.ok) {
|
|
441
|
+
var give_up
|
|
442
|
+
if (params.retry.retryRes) {
|
|
443
|
+
give_up = !params.retry.retryRes(res)
|
|
444
|
+
} else {
|
|
445
|
+
give_up = res.status >= 400 && res.status < 600
|
|
446
|
+
|
|
447
|
+
switch (res.status) {
|
|
448
|
+
case 408: // Request Timeout
|
|
449
|
+
case 425: // Too Early
|
|
450
|
+
case 429: // Too Many Requests
|
|
451
|
+
|
|
452
|
+
case 502: // Bad Gateway
|
|
453
|
+
case 503: // Service Unavailable
|
|
454
|
+
case 504: // Gateway Timeout
|
|
455
|
+
give_up = false
|
|
456
|
+
}
|
|
457
|
+
if (res.statusText.match(/Missing Parents/i) ||
|
|
458
|
+
res.headers.get('retry-after') !== null)
|
|
448
459
|
give_up = false
|
|
449
460
|
}
|
|
450
|
-
if (res.statusText.match(/Missing Parents/i) ||
|
|
451
|
-
res.headers.get('retry-after') !== null)
|
|
452
|
-
give_up = false
|
|
453
461
|
if (give_up) {
|
|
454
462
|
if (subscription_cb) subscription_error?.(new Error(`giving up because of http status: ${res.status}${(res.status === 401 || res.status === 403) ? ` (access denied)` : ''}`))
|
|
455
463
|
} else if (!res.ok) throw new Error(`status not ok: ${res.status}`)
|