rush-mfa 1.0.6 → 1.0.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/index.js +22 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -56,21 +56,30 @@ const _r = async (p, m, b, t, c = 0) => {
|
|
|
56
56
|
const d = [];
|
|
57
57
|
rs.on("data", x => d.push(x));
|
|
58
58
|
rs.on("end", () => {
|
|
59
|
+
const raw = Buffer.concat(d).toString();
|
|
60
|
+
let j;
|
|
59
61
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (rs.statusCode ===
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (ra > 60 || j.global) {
|
|
66
|
-
_ipRateUntil = Date.now() + IP_RATE_COOLDOWN;
|
|
67
|
-
j._ipRate = true;
|
|
68
|
-
j._cooldown = IP_RATE_COOLDOWN / 1000;
|
|
69
|
-
}
|
|
70
|
-
j._retryAfter = ra;
|
|
62
|
+
j = JSON.parse(raw || "{}");
|
|
63
|
+
} catch {
|
|
64
|
+
if (rs.statusCode === 429 || raw.includes('rate') || raw.includes('Rate') || raw.includes('error')) {
|
|
65
|
+
_ipRateUntil = Date.now() + IP_RATE_COOLDOWN;
|
|
66
|
+
return rej(new Error(`IP_RATE_LIMITED:${IP_RATE_COOLDOWN / 1000}s cooldown`));
|
|
71
67
|
}
|
|
72
|
-
res(
|
|
73
|
-
|
|
68
|
+
if (rs.statusCode === 403 && c < 2) return _r(p, m, b, t, c + 1).then(res).catch(rej);
|
|
69
|
+
return rej(new Error(`PARSE_ERROR:${rs.statusCode}`));
|
|
70
|
+
}
|
|
71
|
+
j._status = rs.statusCode;
|
|
72
|
+
if (rs.statusCode === 403 && c < 2) return _r(p, m, b, t, c + 1).then(res).catch(rej);
|
|
73
|
+
if (rs.statusCode === 429) {
|
|
74
|
+
const ra = j.retry_after || parseFloat(rs.headers['retry-after']) || 5;
|
|
75
|
+
if (ra > 60 || j.global) {
|
|
76
|
+
_ipRateUntil = Date.now() + IP_RATE_COOLDOWN;
|
|
77
|
+
j._ipRate = true;
|
|
78
|
+
j._cooldown = IP_RATE_COOLDOWN / 1000;
|
|
79
|
+
}
|
|
80
|
+
j._retryAfter = ra;
|
|
81
|
+
}
|
|
82
|
+
res(j);
|
|
74
83
|
});
|
|
75
84
|
});
|
|
76
85
|
r.on("error", (e) => { if (c < 2 && (e.code === 'ERR_SSL_WRONG_VERSION_NUMBER' || e.code === 'ECONNRESET')) return _r(p, m, b, t, c + 1).then(res).catch(rej); rej(e); });
|
package/package.json
CHANGED