protected function retryDecider()
    {
        return function ($retries, RequestInterface $request, ResponseInterface $response = null) {
            if ($retries >= $this->getMaxRetries()) {
                return false;
            }

            $shouldRetry = false;
            // Retry on server errors
            if (isset($response) && $response->getStatusCode() >= 500) {
                $shouldRetry = true;
            }

            if ($shouldRetry) {
                $this->logNotice(
                    sprintf(
                        'Retrying %s %s %s/%s, %s',
                        $request->getMethod(),
                        $request->getUri(),
                        $retries + 1,
                        $this->getMaxRetries(),
                        $response ? 'status code: ' . $response->getStatusCode() : ''
                    ));
            }

            return $shouldRetry;
        };
    }