tsonik
Version:
A TypeScript client library for the Iconik API based on Swagger documentation
57 lines • 1.81 kB
JavaScript
;
/**
* Retry configuration for HTTP requests
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeRetryConfig = exports.DEFAULT_RETRY_CONFIG = void 0;
exports.DEFAULT_RETRY_CONFIG = {
attempts: 3,
enabled: true,
minDelay: 100,
maxDelay: 30000,
factor: 2,
randomize: 0.1,
// Safe HTTP status codes to retry on
retryOnStatus: [
408, // Request Timeout
429, // Too Many Requests
500, // Internal Server Error
502, // Bad Gateway
503, // Service Unavailable
504, // Gateway Timeout
520, // Web Server Returned an Unknown Error
521, // Web Server Is Down
522, // Connection Timed Out
523, // Origin Is Unreachable
524, // A Timeout Occurred
],
// Only retry safe HTTP methods by default
retryOnMethods: ['GET', 'HEAD', 'OPTIONS'],
// Network error codes that are safe to retry
retryOnNetworkErrors: [
'ECONNRESET',
'ENOTFOUND',
'ECONNREFUSED',
'ETIMEDOUT',
'ECONNABORTED',
'EHOSTUNREACH',
'ENETUNREACH',
'EAI_AGAIN',
],
// Default retry condition (can be overridden)
shouldRetry: () => true,
};
/**
* Merge user config with defaults
*/
function mergeRetryConfig(userConfig = {}) {
return {
...exports.DEFAULT_RETRY_CONFIG,
...userConfig,
retryOnStatus: userConfig.retryOnStatus ?? exports.DEFAULT_RETRY_CONFIG.retryOnStatus,
retryOnMethods: userConfig.retryOnMethods ?? exports.DEFAULT_RETRY_CONFIG.retryOnMethods,
retryOnNetworkErrors: userConfig.retryOnNetworkErrors ?? exports.DEFAULT_RETRY_CONFIG.retryOnNetworkErrors,
};
}
exports.mergeRetryConfig = mergeRetryConfig;
//# sourceMappingURL=config.js.map