func (m retryMiddleware) RoundTrip(req *http.Request) (*http.Response, error) {
	var (
		res        *http.Response
		backOffErr error
	)
	err := retry.Call(retry.CallArgs{
		Clock: m.clock,
		Func: func() error {
			if err := req.Context().Err(); err != nil {
				return err
			}
			if backOffErr != nil {
				return backOffErr
			}

			var retryable bool
			var err error
			res, retryable, err = m.roundTrip(req)
			if err != nil {
				return err
			}
			if retryable {
				return retryableErr{}
			}
			return nil
		},
		IsFatalError: func(err error) bool {
			// Work out if it's not a retryable error.
			_, ok := errors.Cause(err).(retryableErr)
			return !ok
		},
		Attempts: m.policy.Attempts,
		Delay:    m.policy.Delay,
		BackoffFunc: func(delay time.Duration, attempts int) time.Duration {
			var duration time.Duration
			duration, backOffErr = m.defaultBackoff(res, delay)
			return duration
		},
	})

	return res, err
}
// RoundTrip defines a strategy for handling retries based on the status code.
RoundTrip defines a strategy for handling retries based on the status code.
// RoundTrip defines a strategy for handling retries based on the status code .
func (m retryMiddleware) RoundTrip(req *http.Request) (*http.Response, error) {
	var (
		res        *http.Response
		backOffErr error
	)
	err := retry.Call(retry.CallArgs{
		Clock: m.clock,
		Func: func() error {
			if err := req.Context().Err(); err != nil {
				return err
			}
			if backOffErr != nil {
				return backOffErr
			}
			var retryable bool
			var err error
			res, retryable, err = m.roundTrip(req)
			if err != nil {
				return err
			}
			if retryable {
				return retryableErr{}
			}
			return nil
		},
		IsFatalError: func(err error) bool {
			_, ok := errors.Cause(err).(retryableErr)
			return !ok
		},
		Attempts: m.policy.Attempts,
		Delay:    m.policy.Delay,
		BackoffFunc: func(delay time.Duration, attempts int) time.Duration {
			var duration time.Duration
			duration, backOffErr = m.defaultBackoff(res, delay)
			return duration
		},
	})
	return res, err
}
func ( m retryMiddleware ) RoundTrip ( req * http . Request ) ( * http . Response , error ) { var ( res * http . Response backOffErr error ) err := retry . Call ( retry . CallArgs { Clock : m . clock , Func : func ( ) error { if err := req . Context ( ) . Err ( ) ; err != nil { return err } if backOffErr != nil { return backOffErr } var retryable bool var err error res , retryable , err = m . roundTrip ( req ) if err != nil { return err } if retryable { return retryableErr { } } return nil } , IsFatalError : func ( err error ) bool { _ , ok := errors . Cause ( err ) . ( retryableErr ) return ! ok } , Attempts : m . policy . Attempts , Delay : m . policy . Delay , BackoffFunc : func ( delay time . Duration , attempts int ) time . Duration { var duration time . Duration duration , backOffErr = m . defaultBackoff ( res , delay ) return duration } , } ) return res , err }
RoundTrip defines a strategy for handling retries based on the status code.
RoundTrip defines a strategy for handling retries based on the status code .
// Work out if it's not a retryable error.