Returns a responder that deals with failed HTTP requests.

@param \Throwable  $throwable the error the request has caused.
@param HttpRequest $request   the request that has not been
satisfied.
430417
private static function getHttpErrorResponder(\Throwable $throwable, HttpRequest $request = null)
    {
        // If an error request has been made, oblige.
        $responder = new \Eix\Core\Responders\Http\Error($request);
        $responder->setThrowable($throwable);

        return $responder;
    }
669300
public function doRequest(HttpRequestInterface $request)
    {
        $responseClass = $this->responseClass;

        /** @var HttpResponseInterface $responseObject */
        $responseObject = new $responseClass();

        return $responseObject->build($request);
    }
1126047
public function handleRequest(ServiceRequestInterface $request, $resource = null)
    {
        $this->setRequest($request);
        $this->setAction($request->getMethod());
        $this->setResourceMembers($resource);
        $this->response = null;

        $resources = $this->getResourceHandlers();
        if (!empty($resources) && !empty($this->resource)) {
            try {
                if (false === $this->response = $this->handleResource($resources)) {
                    $message = ucfirst($this->action) . " requests for resource '{$this->resourcePath}' are not currently supported by the '{$this->name}' service.";
                    throw new BadRequestException($message);
                }

                if (!($this->response instanceof ServiceResponseInterface ||
                    $this->response instanceof RedirectResponse ||
                    $this->response instanceof StreamedResponse
                )
                ) {
                    $this->response = ResponseFactory::create($this->response);
                }
            } catch (\Exception $e) {
                $this->response = static::exceptionToServiceResponse($e);
            }

            return $this->response;
        }

        try {
            //  Perform any pre-processing
            $this->preProcess();

            // pre-process can now create a response along with throw exceptions to circumvent the processRequest
            if (null === $this->response) {
                if (false === $this->response = $this->processRequest()) {
                    $message = ucfirst($this->action) . " requests without a resource are not currently supported by the '{$this->name}' service.";
                    throw new BadRequestException($message);
                }
            }

            if (!($this->response instanceof ServiceResponseInterface ||
                $this->response instanceof RedirectResponse ||
                $this->response instanceof StreamedResponse
            )
            ) {
                $this->response = ResponseFactory::create($this->response);
            }
        } catch (\Exception $e) {
            $this->response = static::exceptionToServiceResponse($e);
        }

        //  Perform any post-processing
        try {
            $this->postProcess();
        } catch (\Exception $e) {
            // override the actual response with the exception
            $this->response = static::exceptionToServiceResponse($e);
        }

        //  Perform any response processing
        return $this->respond();
    }
67434
public function serverError(\Throwable $exception, ServerRequestInterface $request) : ResponseInterface
    {
        $this->exception = $exception;

        $acceptType = $request->getHeader('Accept');
        if (is_array($acceptType) && count($acceptType) > 0 && strpos($acceptType[0], 'json') !== false) {
            return new JsonResponse(['error' => ['message' => $exception->getMessage(), 'type' => 'Exception', 'trace' => $this->debugMode ? $exception->getTraceAsString() : '']], 500);
        }

        if ($this->contentFor500) {
            $this->contentBlock->addHtmlElement($this->contentFor500);
        } else {
            $this->contentBlock->addFile(__DIR__ . '/../../../../views/500.php', $this);
        }

        return HtmlResponse::create($this->template, 500);
    }
566551
public static function getResponder(Request $request)
    {
        if ($request instanceof HttpRequest) {
            return self::getHttpResponder($request);
        } else {
            $requestType = get_class($request);
            throw new \InvalidArgumentException("Requests of type '{$requestType}' are not supported.");
        }
    }
392234
public function handleException(\Throwable $throwable)
    {
        // Captured an application-level exception.
        try {
            // Log the exception.
            Logger::get()->exception($throwable);
            // Try to display a user-friendly message.
            $responder = new Responders\Http\Error;
            $responder->setThrowable($throwable);
            $responder->getResponse()->issue();
            // Stop the application, as it did not handle the exception
            // properly.
            die(-1);
        } catch (\Exception $innerException) {
            $this->fail($innerException);
        }
    }
20440
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $errorPageConfig = Config::getInstance()->get('errorPage');
        $controllerClass = '\\app\\Controllers\\' . $errorPageConfig[0];
        $route = new Route('404', $errorPageConfig[0], $errorPageConfig[1]);
        $controller = new $controllerClass($route, $request);
        $response = new Response;
        ob_start();
        $controller->execute();
        $responseController = ob_get_clean();
        $response->getBody()->write($responseController);
        $response = $response->withStatus(404);
        $logger = new Logger();
        $logger->info('Error 404, NotFoundMiddleware');
        return $response;
    }
436822
public function handle($throwable)
    {
        if ($throwable instanceof Exception) {
            $response = $this->handler->handleException($this->defaultRequest, $this->defaultResponse, $throwable);
        } elseif ($throwable instanceof Throwable) {
            $response = $this->handler->handleThrowable($this->defaultRequest, $this->defaultResponse, $throwable);
        } else {
            return false;
        }

        if ($response instanceof ResponseInterface) {
            $this->renderResponse($response);
            return true;
        } else {
            return false;
        }
    }
712132
public function sendRequest(Http\Request $httpRequest)
    {
        $requestHandler = $this->bootstrap->getActiveRequestHandler();
        if (!$requestHandler instanceof FunctionalTestRequestHandler) {
            throw new Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
        }

        $this->securityContext->clearContext();
        $this->validatorResolver->reset();

        $response = new Http\Response();
        $componentContext = new ComponentContext($httpRequest, $response);
        $requestHandler->setComponentContext($componentContext);

        $objectManager = $this->bootstrap->getObjectManager();
        $baseComponentChain = $objectManager->get(\Neos\Flow\Http\Component\ComponentChain::class);
        $componentContext = new ComponentContext($httpRequest, $response);

        try {
            $baseComponentChain->handle($componentContext);
        } catch (\Throwable $throwable) {
            $this->prepareErrorResponse($throwable, $componentContext->getHttpResponse());
        } catch (\Exception $exception) {
            $this->prepareErrorResponse($exception, $componentContext->getHttpResponse());
        }
        $session = $this->bootstrap->getObjectManager()->get(SessionInterface::class);
        if ($session->isStarted()) {
            $session->close();
        }
        $this->persistenceManager->clearState();
        return $componentContext->getHttpResponse();
    }
327096
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if (empty($this->handler)) {
            throw new HttpException("Unable to run HttpCore, no handler is set.");
        }

        return $this->pipeline->withHandler($this->handler)->handle($request);
    }
633574
public function handle($request) : ResponseInterface
    {
        $this->setRouter($request);

        try {
            $response = $this->sendRequestThroughRouter($request);
            /*
             * Check whether return value is a instance of Response,
             * otherwise we will try to fetch the response form container,
             * create a response and return to the browser.
             *
             */
            if (!$response instanceof ResponseInterface && !is_array($response)) {
                $r = $this->container->has('response') ? $this->container->get('response') : '';
                $response = Response::make($r);
            }
        } catch (\Exception $e) {
            $this->handleException($e);
        } catch (Throwable $e) {
            $this->handleException($e);
        }

        return $response;
    }
123997
public function handle(Request $request): Response
    {
        try {
            $matcher = $this->getUrlMatcher($request);

            $parameters = $matcher->match($request->getPathInfo());

            if (empty($parameters['_controller'])) {
                throw new InvalidRouteException('Route requires a _controller callable');
            }

            if (!\is_callable($parameters['_controller'])) {
                throw new InvalidRouteException('_controller must be a callable');
            }

            $callback = $parameters['_controller'];

            $result = call_user_func_array($callback, $this->getControllerParameters($request, $parameters));

            if (!$result instanceof Response) {
                throw new InvalidResponseException('Response must be an instance of \Symfony\Component\HttpFoundation\Response');
            }
        } catch (\Exception $e) {
            $result = $this->handleException($request, $e);
        }

        return $result;
    }
317563
protected function doRequest(RequestInterface $httpRequest)
    {
        $httpRawResponse = $httpRequest->execute();
        $httpStatusCode = $httpRequest->getInfo(CURLINFO_HTTP_CODE);
        $httpRequest->close();

        return $this->buildResponse($httpStatusCode, $httpRawResponse);
    }
1276701
public function handleException(\Throwable $throwable, bool $debug = false): ResponseInterface
    {
        $apiError = Error::createFrom($throwable, $debug);

        $document = $this->singleResourceDocument();
        $document->errors()->add($apiError);


        return new DocumentResponse($document, null, $apiError->status());
    }
452481
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);
        $details = ArrayObject::ensureArrayObject($request->getModel());

        $httpRequest = new GetHttpRequest();
        $this->gateway->execute($httpRequest);

        if ($this->api->verifyHash($httpRequest->request) === false) {
            throw new HttpResponse('0|CheckMacValue verify fail.', 400, ['Content-Type' => 'text/plain']);
        }

        $details->replace($httpRequest->request);

        throw new HttpResponse('1|OK', 200, ['Content-Type' => 'text/plain']);
    }
482851
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $matcher = $this->routerContainer->getMatcher();
        $route = $matcher->match($request);

        if (!$route instanceof Route) {
            return $this->handleFailedRoute($matcher->getFailedRoute());
        }

        $request = $request->withAttribute('route', $route);
        return $handler->handle($request);
    }
434039
protected function handleErrorResponses(HttpException $exception)
    {
        $status = $exception->getCode();
        $message = $exception->getStatusMessage();
        $solrRespone = new ResponseAdapter($exception->getBody());

        if ($status === 0 || $status === 502) {
            $e = new SolrUnavailableException('Solr Server not available: ' . $message, 1505989391);
            $e->setSolrResponse($solrRespone);
            throw $e;
        }

        if ($status === 500) {
            $e = new SolrInternalServerErrorException('Internal Server error during search: ' . $message, 1505989897);
            $e->setSolrResponse($solrRespone);
            throw $e;
        }

        $e = new SolrCommunicationException('Invalid query. Solr returned an error: ' . $status . ' ' . $message, 1293109870);
        $e->setSolrResponse($solrRespone);

        throw $e;
    }