protected function onFailure(RequestInterface $request)
    {
        return function ($reason) use ($request) {

            // Only log a rejected requests if it hasn't already been logged
            $this->log($request, null, $reason);

            return Promise\rejection_for($reason);
        };
    }