style: format shared http refactor
This commit is contained in:
@@ -1071,7 +1071,11 @@ export default async function fetchFacebookItems(
|
|||||||
logger.warn(
|
logger.warn(
|
||||||
`\nFacebook marketplace access failed (${err.statusCode}): ${err.message}`,
|
`\nFacebook marketplace access failed (${err.statusCode}): ${err.message}`,
|
||||||
);
|
);
|
||||||
if (err.statusCode === 400 || err.statusCode === 401 || err.statusCode === 403) {
|
if (
|
||||||
|
err.statusCode === 400 ||
|
||||||
|
err.statusCode === 401 ||
|
||||||
|
err.statusCode === 403
|
||||||
|
) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"This might indicate invalid or expired cookies. Update FACEBOOK_COOKIE with a fresh raw Cookie header string.",
|
"This might indicate invalid or expired cookies. Update FACEBOOK_COOKIE with a fresh raw Cookie header string.",
|
||||||
);
|
);
|
||||||
@@ -1079,9 +1083,7 @@ export default async function fetchFacebookItems(
|
|||||||
return finalizeResults([]);
|
return finalizeResults([]);
|
||||||
}
|
}
|
||||||
if (err instanceof RateLimitError) {
|
if (err instanceof RateLimitError) {
|
||||||
logger.warn(
|
logger.warn(`\nFacebook marketplace access rate limited: ${err.message}`);
|
||||||
`\nFacebook marketplace access rate limited: ${err.message}`,
|
|
||||||
);
|
|
||||||
return finalizeResults([]);
|
return finalizeResults([]);
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
@@ -161,7 +161,11 @@ export async function fetchHtml(
|
|||||||
: Number.NaN;
|
: Number.NaN;
|
||||||
const waitMs = Number.isFinite(resetSeconds)
|
const waitMs = Number.isFinite(resetSeconds)
|
||||||
? Math.max(0, resetSeconds * 1000)
|
? Math.max(0, resetSeconds * 1000)
|
||||||
: calculateBackoffDelay(attempt, retryBaseMs, opts?.jitter ?? Math.random);
|
: calculateBackoffDelay(
|
||||||
|
attempt,
|
||||||
|
retryBaseMs,
|
||||||
|
opts?.jitter ?? Math.random,
|
||||||
|
);
|
||||||
|
|
||||||
if (attempt < maxRetries) {
|
if (attempt < maxRetries) {
|
||||||
await delay(waitMs);
|
await delay(waitMs);
|
||||||
@@ -176,7 +180,13 @@ export async function fetchHtml(
|
|||||||
|
|
||||||
// Retry on server errors
|
// Retry on server errors
|
||||||
if (res.status >= 500 && res.status < 600 && attempt < maxRetries) {
|
if (res.status >= 500 && res.status < 600 && attempt < maxRetries) {
|
||||||
await delay(calculateBackoffDelay(attempt, retryBaseMs, opts?.jitter ?? Math.random));
|
await delay(
|
||||||
|
calculateBackoffDelay(
|
||||||
|
attempt,
|
||||||
|
retryBaseMs,
|
||||||
|
opts?.jitter ?? Math.random,
|
||||||
|
),
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +216,13 @@ export async function fetchHtml(
|
|||||||
|
|
||||||
if (err instanceof Error && err.name === "AbortError") {
|
if (err instanceof Error && err.name === "AbortError") {
|
||||||
if (attempt < maxRetries) {
|
if (attempt < maxRetries) {
|
||||||
await delay(calculateBackoffDelay(attempt, retryBaseMs, opts?.jitter ?? Math.random));
|
await delay(
|
||||||
|
calculateBackoffDelay(
|
||||||
|
attempt,
|
||||||
|
retryBaseMs,
|
||||||
|
opts?.jitter ?? Math.random,
|
||||||
|
),
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
throw new NetworkError(`Request timeout for ${url}`, url, err);
|
throw new NetworkError(`Request timeout for ${url}`, url, err);
|
||||||
@@ -214,7 +230,13 @@ export async function fetchHtml(
|
|||||||
|
|
||||||
// Network or other errors
|
// Network or other errors
|
||||||
if (attempt < maxRetries) {
|
if (attempt < maxRetries) {
|
||||||
await delay(calculateBackoffDelay(attempt, retryBaseMs, opts?.jitter ?? Math.random));
|
await delay(
|
||||||
|
calculateBackoffDelay(
|
||||||
|
attempt,
|
||||||
|
retryBaseMs,
|
||||||
|
opts?.jitter ?? Math.random,
|
||||||
|
),
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
throw new NetworkError(
|
throw new NetworkError(
|
||||||
|
|||||||
Reference in New Issue
Block a user