private function issueResponse(Request $request, \Exception $exception = null)
    {
        $responder = null;
        if ($exception === null) {
            // No exception, just return a normal responder.
            $responder = ResponderFactory::getResponder($request);
        } else {
            // Any type of exception, just find an error responder.
            $responder = ResponderFactory::getErrorResponder($request, $exception);
        }
        // The responder is asked to produce a Response object, which is then
        // asked to perform whatever actions it takes to issue the response.

        try {
            $response = $responder->getResponse();
        } catch (NotAuthenticatedException $exception) {
            // A resource that needs authentication was hit.

            // Store the current locator, to be able to return to it after
            // signing in.
            $this->keepCurrentLocator($request);
            // Request identification from the user.
            // Set the method to GET for the identity request. POST is reserved
            // for the actual posting of the identity data by the user.
            $request->setMethod(HttpRequest::HTTP_METHOD_GET);
            $responder = new IdentityResponder($request);
            $response = $responder->getResponse();
        }

        if ($response instanceof Response) {
            // Provide a hook for last-minute response work.
            $this->alterResponse($response);
            // Issue the response.
            $response->issue();
        } else {
            throw new HttpException('No response available.');
        }
    }