@solarisdk/browser 0.1.6 → 0.1.7
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/dist/index.js +15 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -109,15 +109,19 @@ async function responseSaysRetryable(res) {
|
|
|
109
109
|
return false;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
//
|
|
113
|
-
// code from the caller.
|
|
112
|
+
// Some 5xx are answers, not outages: retrying cannot change them, and swallowing the body would hide the
|
|
113
|
+
// code from the caller. The gateway says so itself with `retryable: false` (502 `PoolResponseUnparseable`:
|
|
114
|
+
// the session may already exist, so a retry creates a second one; 503 `EgressBlockPeekUnsupportedOnFlavor`).
|
|
115
|
+
// `ProxyTierUnavailable` (explicitly requested proxy tier not servable) is also terminal, whatever its flag.
|
|
114
116
|
const TERMINAL_503_CODES = new Set(["ProxyTierUnavailable"]);
|
|
115
|
-
async function
|
|
116
|
-
if (res.status !== 503)
|
|
117
|
-
return false;
|
|
117
|
+
async function responseIsTerminal(res) {
|
|
118
118
|
try {
|
|
119
119
|
const body = (await res.clone().json());
|
|
120
|
-
|
|
120
|
+
if (body?.retryable === false)
|
|
121
|
+
return true;
|
|
122
|
+
return (res.status === 503 &&
|
|
123
|
+
typeof body?.code === "string" &&
|
|
124
|
+
TERMINAL_503_CODES.has(body.code));
|
|
121
125
|
}
|
|
122
126
|
catch {
|
|
123
127
|
return false;
|
|
@@ -575,10 +579,13 @@ export class Solari {
|
|
|
575
579
|
clearTimeout(timer);
|
|
576
580
|
if (res.ok)
|
|
577
581
|
return res;
|
|
578
|
-
const retryThis = (isRetryableStatus(res.status) && !(await
|
|
582
|
+
const retryThis = (isRetryableStatus(res.status) && !(await responseIsTerminal(res))) ||
|
|
579
583
|
(isSafeToReplay(method, opts?.idempotencyKey) &&
|
|
580
584
|
(await responseSaysRetryable(res)));
|
|
581
|
-
|
|
585
|
+
// Out of attempts: hand the last response back so the caller maps its
|
|
586
|
+
// status and `code` like any other error, instead of a status-less
|
|
587
|
+
// "exhausted" error that hides why the gateway refused.
|
|
588
|
+
if (!retryThis || attempt === this.maxAttempts)
|
|
582
589
|
return res;
|
|
583
590
|
await res.text().catch(() => { });
|
|
584
591
|
lastErr = new SolariError(`Solari ${method} ${path}: ${res.status}`, res.status);
|