(opts, { dispatch, handler })
| 16 | |
| 17 | class RetryHandler { |
| 18 | constructor (opts, { dispatch, handler }) { |
| 19 | const { retryOptions, ...dispatchOpts } = opts |
| 20 | const { |
| 21 | // Retry scoped |
| 22 | retry: retryFn, |
| 23 | maxRetries, |
| 24 | maxTimeout, |
| 25 | minTimeout, |
| 26 | timeoutFactor, |
| 27 | // Response scoped |
| 28 | methods, |
| 29 | errorCodes, |
| 30 | retryAfter, |
| 31 | statusCodes, |
| 32 | throwOnError |
| 33 | } = retryOptions ?? {} |
| 34 | |
| 35 | this.error = null |
| 36 | this.dispatch = dispatch |
| 37 | this.handler = handler |
| 38 | this.opts = { ...dispatchOpts, body: wrapRequestBody(opts.body) } |
| 39 | this.retryOpts = { |
| 40 | throwOnError: throwOnError ?? true, |
| 41 | retry: retryFn ?? RetryHandler[kRetryHandlerDefaultRetry], |
| 42 | retryAfter: retryAfter ?? true, |
| 43 | maxTimeout: maxTimeout ?? 30 * 1000, // 30s, |
| 44 | minTimeout: minTimeout ?? 500, // .5s |
| 45 | timeoutFactor: timeoutFactor ?? 2, |
| 46 | maxRetries: maxRetries ?? 5, |
| 47 | // What errors we should retry |
| 48 | methods: methods ?? ['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE'], |
| 49 | // Indicates which errors to retry |
| 50 | statusCodes: statusCodes ?? [500, 502, 503, 504, 429], |
| 51 | // List of errors to retry |
| 52 | errorCodes: errorCodes ?? [ |
| 53 | 'ECONNRESET', |
| 54 | 'ECONNREFUSED', |
| 55 | 'ENOTFOUND', |
| 56 | 'ENETDOWN', |
| 57 | 'ENETUNREACH', |
| 58 | 'EHOSTDOWN', |
| 59 | 'EHOSTUNREACH', |
| 60 | 'EPIPE', |
| 61 | 'UND_ERR_SOCKET' |
| 62 | ] |
| 63 | } |
| 64 | |
| 65 | this.retryCount = 0 |
| 66 | this.retryCountCheckpoint = 0 |
| 67 | this.headersSent = false |
| 68 | this.start = 0 |
| 69 | this.end = null |
| 70 | this.etag = null |
| 71 | this.statusCode = null |
| 72 | this.headers = null |
| 73 | } |
| 74 | |
| 75 | onResponseStartWithRetry (controller, statusCode, headers, statusMessage, err) { |
nothing calls this directly
no test coverage detected