private static function retryDecider()
    {
        return function (
            $retries,
            Request $request,
            Response $response = null,
            RequestException $exception = null
        ) {
            // Limit the number of retries to 10
            if ($retries >= 10) {
                return false;
            }

            // Retry connection exceptions
            if ($exception instanceof ConnectException) {
                return true;
            }

            if ($response) {
                // Retry on server errors or overload
                $statusCode = $response->getStatusCode();
                if (429 == $statusCode || 504 == $statusCode || 503 == $statusCode || 502 == $statusCode) {
                    return true;
                }
            }

            return false;
        };
    }