thebird 1.2.62 → 1.2.63
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/docs/vendor/thebird-browser.js +15 -1
- package/lib/errors.js +15 -1
- package/package.json +1 -1
|
@@ -18209,6 +18209,19 @@ var require_errors = __commonJS({
|
|
|
18209
18209
|
const msg = err?.message ?? "";
|
|
18210
18210
|
return /quota|rate.?limit|overloaded|unavailable/i.test(msg);
|
|
18211
18211
|
}
|
|
18212
|
+
function parseRetryDelay(err) {
|
|
18213
|
+
try {
|
|
18214
|
+
const body = typeof err.message === "string" ? JSON.parse(err.message) : err.message;
|
|
18215
|
+
const details = body?.error?.details || [];
|
|
18216
|
+
const retryInfo = details.find((d) => d["@type"]?.includes("RetryInfo"));
|
|
18217
|
+
if (retryInfo?.retryDelay) {
|
|
18218
|
+
const secs = parseFloat(retryInfo.retryDelay);
|
|
18219
|
+
if (!isNaN(secs)) return secs * 1e3;
|
|
18220
|
+
}
|
|
18221
|
+
} catch (_) {
|
|
18222
|
+
}
|
|
18223
|
+
return null;
|
|
18224
|
+
}
|
|
18212
18225
|
async function withRetry(fn, maxRetries = 3) {
|
|
18213
18226
|
let lastErr;
|
|
18214
18227
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
@@ -18217,7 +18230,8 @@ var require_errors = __commonJS({
|
|
|
18217
18230
|
} catch (err) {
|
|
18218
18231
|
lastErr = err;
|
|
18219
18232
|
if (!isRetryable(err) || attempt === maxRetries) throw err;
|
|
18220
|
-
const
|
|
18233
|
+
const suggested = parseRetryDelay(err);
|
|
18234
|
+
const delay = suggested != null ? suggested + Math.random() * 1e3 : Math.min(1e3 * 2 ** attempt + Math.random() * 200, 16e3);
|
|
18221
18235
|
await new Promise((r) => setTimeout(r, delay));
|
|
18222
18236
|
}
|
|
18223
18237
|
}
|
package/lib/errors.js
CHANGED
|
@@ -17,6 +17,19 @@ function isRetryable(err) {
|
|
|
17
17
|
return /quota|rate.?limit|overloaded|unavailable/i.test(msg);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
function parseRetryDelay(err) {
|
|
21
|
+
try {
|
|
22
|
+
const body = typeof err.message === 'string' ? JSON.parse(err.message) : err.message;
|
|
23
|
+
const details = body?.error?.details || [];
|
|
24
|
+
const retryInfo = details.find(d => d['@type']?.includes('RetryInfo'));
|
|
25
|
+
if (retryInfo?.retryDelay) {
|
|
26
|
+
const secs = parseFloat(retryInfo.retryDelay);
|
|
27
|
+
if (!isNaN(secs)) return secs * 1000;
|
|
28
|
+
}
|
|
29
|
+
} catch (_) {}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
20
33
|
async function withRetry(fn, maxRetries = 3) {
|
|
21
34
|
let lastErr;
|
|
22
35
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
@@ -25,7 +38,8 @@ async function withRetry(fn, maxRetries = 3) {
|
|
|
25
38
|
} catch (err) {
|
|
26
39
|
lastErr = err;
|
|
27
40
|
if (!isRetryable(err) || attempt === maxRetries) throw err;
|
|
28
|
-
const
|
|
41
|
+
const suggested = parseRetryDelay(err);
|
|
42
|
+
const delay = suggested != null ? suggested + Math.random() * 1000 : Math.min(1000 * 2 ** attempt + Math.random() * 200, 16000);
|
|
29
43
|
await new Promise(r => setTimeout(r, delay));
|
|
30
44
|
}
|
|
31
45
|
}
|
package/package.json
CHANGED