@dividenconquer/cloudflare-proxy-fetch
Version:
A robust HTTP/HTTPS proxy client implementation for Cloudflare Workers with automatic retries and proxy rotation
42 lines • 1.86 kB
JavaScript
/**
* Regular expression patterns to detect proxy blocking and connection issues.
* These patterns cover common error messages and status codes that indicate
* proxy-related failures.
*/
export const BLOCKED_PATTERNS = [
/proxy.*(?:blocked|denied|rejected)/i, // Proxy blocking/denial messages
/(?:connection.*refused|refused.*connection)/i, // Connection failures
/(?:timeout|timed.*out)/i, // Timeout messages
/(?:forbidden|403)/i, // Forbidden responses
/(?:407|proxy.*auth.*required)/i, // Proxy authentication required
/(?:502|bad.*gateway)/i, // Bad gateway errors
/(?:504|gateway.*timeout)/i, // Gateway timeout errors
];
/**
* Determines if an error is related to proxy connection issues.
*
* This function checks both HTTP status codes and error message patterns
* to identify proxy-specific connection problems.
*
* @param error - The error to analyze (can be Error object, string, or unknown)
* @returns boolean - True if the error is proxy-related, false otherwise
*/
export function isProxyConnectionError(error) {
// Check for specific HTTP status codes in Error objects
if (error instanceof Error && "statusCode" in error) {
// @ts-ignore - statusCode is a custom property added to Error objects
const statusCode = error.statusCode;
// Common proxy-related HTTP status codes:
// 407: Proxy Authentication Required
// 403: Forbidden (Access denied by proxy)
// 502: Bad Gateway (Proxy server error)
// 504: Gateway Timeout (Proxy timeout)
if ([407, 403, 502, 504].includes(statusCode)) {
return true;
}
}
// Check error message against known proxy error patterns
const errorStr = String(error);
return BLOCKED_PATTERNS.some((pattern) => pattern.test(errorStr));
}
//# sourceMappingURL=index.js.map