azure-storage-common/src/Common/Middlewares/RetryMiddlewareFactory.php
protected static function createRetryDecider($type, $maxRetries, $retryConnect)
    {
        return function (
            $retries,
            $request,
            $response = null,
            $exception = null,
            $isSecondary = false
        ) use (
            $type,
            $maxRetries,
            $retryConnect
        ) {
            //Exceeds the retry limit. No retry.
            if ($retries >= $maxRetries) {
                return false;
            }

            if (!$response) {
                if (!$exception || !($exception instanceof RequestException)) {
                    return false;
                } elseif ($exception instanceof ConnectException) {
                    return $retryConnect;
                } else {
                    $response = $exception->getResponse();
                }
            }

            if ($type == self::GENERAL_RETRY_TYPE) {
                return self::generalRetryDecider(
                    $response->getStatusCode(),
                    $isSecondary
                );
            } else {
                return self::appendBlobRetryDecider(
                    $response->getStatusCode(),
                    $isSecondary
                );
            }

            return true;
        };
    }
protected static function createRetryDecider($type, $maxRetries, $retryConnect)
    {
        return function (
            $retries,
            $request,
            $response = null,
            $exception = null,
            $isSecondary = false
        ) use (
            $type,
            $maxRetries,
            $retryConnect
        ) {
            //Exceeds the retry limit. No retry.
            if ($retries >= $maxRetries) {
                return false;
            }

            if (!$response) {
                if (!$exception || !($exception instanceof RequestException)) {
                    return false;
                } elseif ($exception instanceof ConnectException) {
                    return $retryConnect;
                } else {
                    $response = $exception->getResponse();
                }
            }

            if ($type == self::GENERAL_RETRY_TYPE) {
                return self::generalRetryDecider(
                    $response->getStatusCode(),
                    $isSecondary
                );
            } else {
                return self::appendBlobRetryDecider(
                    $response->getStatusCode(),
                    $isSecondary
                );
            }

            return true;
        };
    }
Create the retry decider for the retry handler. It will return a callable
that accepts the number of retries, the request, the response and the
exception, and return the decision for a retry.

@param  string $type         The type of the retry handler.
@param  int    $maxRetries   The maximum number of retries to be done.
@param  bool   $retryConnect Whether to retry on connection failures.

@return callable     The callable that will return if the request should
be retried.