Maps this exception to a response object.

@return Response this exception maps to.
947
public static Response toResponse(Response.Status status, String wwwAuthHeader) {
        Response.ResponseBuilder rb = Response.status(status);
        if (wwwAuthHeader != null) {
            rb.header("WWW-Authenticate", wwwAuthHeader);
        }
        return rb.build();
    }
88176
public function fromException( Exception $exception )
    {
        $response = new HttpResponse();
        $response->setStatusCode( 200 );
        $response->headers->set( 'Content-Type', 'text/xml' );
        $response->setContent( $this->generateXmlFromException( $exception ) );
        return $response;
    }
571926
public function fulfillRequest()
    {
        if (! $this->supportsMethod($this->request->method)) {
            throw new Exception(
                'Method not allowed',
                static::ERROR_SCOPE | static::ERROR_HTTP_METHOD_NOT_ALLOWED,
                BaseResponse::HTTP_METHOD_NOT_ALLOWED
            );
        }

        $methodName = static::methodHandlerName($this->request->method);
        $models = $this->{$methodName}($this->request);

        if (is_null($models)) {
            throw new Exception(
                'Unknown ID',
                static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
                BaseResponse::HTTP_NOT_FOUND
            );
        }

        if ($models instanceof Response) {
            $response = $models;
        } elseif ($models instanceof LengthAwarePaginator) {
            $items = new Collection($models->items());
            foreach ($items as $model) {
                $this->loadRelatedModels($model);
            }

            $response = new Response($items, static::successfulHttpStatusCode($this->request->method));

            $response->links = $this->getPaginationLinks($models);
            $response->included = $this->getIncludedModels($items);
            $response->errors = $this->getNonBreakingErrors();
        } else {
            if ($models instanceof Collection) {
                foreach ($models as $model) {
                    $this->loadRelatedModels($model);
                }
            } else {
                $this->loadRelatedModels($models);
            }

            $response = new Response($models, static::successfulHttpStatusCode($this->request->method, $models));

            $response->included = $this->getIncludedModels($models);
            $response->errors = $this->getNonBreakingErrors();
        }

        return $response;
    }
543151
public function me()
    {
        $path = self::ME_PATH;

        $response = $this->execute($path, HttpVerb::GET, null);

        $result = null;
        if ($response->getCode() == 200) {
            $responseArray = $this->decodeData($response);
            $result        = $responseArray;
        } else {
            $this->handleError($response);
        }

        return $result;
    }
791848
public function translateResponseToException(\Amp\Artax\Response $response) {
        $status = $response->getStatus();
        if ($status < 200 || $status >= 300) {
            return new BadResponseException(
                "Status $status is not treated as OK.",
                $response
            );
        }

        return null;
    }
68582
public function format(\Exception $exception)
    {
        $response = new Response();

        try {
            $response = $this->serialize(
                $this->config->isDebug() ? new Entity\DebugError($exception) : new Entity\Error($exception),
                is_null($this->request) ? Request::createFromGlobals() : $this->request,
                $response
            );
        } catch (\Exception $e) {
            $response->setContent(
                $this->serviceHateoas()->getSerializer()->serialize(
                    $this->config->isDebug() ? new Entity\DebugError($e) : new Entity\Error($e),
                    'json'
                )
            );

            $vendor = $this->getContainer()->get(Application::CONTAINER_ID_VENDOR);
            $apiVersion = $this->getContainer()->get(Application::CONTAINER_ID_API_VERSION);

            $response->headers->set('Content-Type', 'application/vnd.' . $vendor . '-v' . $apiVersion . '+json');
        }

        $response->setStatusCode(method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500);

        $response->sendHeaders();

        return $response->getContent();
    }
558010
public function send()
    {
        if ($this->sent === false) {
            $this->sendHeaders();
            $this->sendCookies();

            $content = (string)$this->getBody();
            if (!empty($content)) {
                echo $content;
            } else {
                if (is_string($this->file)) {
                    if (!file_exists($this->file)) {
                        throw new Exception('The requested file was not found');
                    }
                    $handle = fopen($this->file, 'r');

                    if ($handle !== false) {
                        fpassthru($handle);
                        fclose($handle);
                    }
                }
            }

            $this->sent = true;

            return $this;
        }

        throw new Exception('Response was already sent');
    }
1351311
public function toArray()
    {
        if ($this->getResponseType() == 'application/json')
        {
            $response = $this->convertJsonToArray($this->getBody());
        }
        elseif ($this->getResponseType() == 'application/binary')
        {
            $response = $this->convertSerializedToArray($this->getBody());
        }
        else
        {
            $response = null;
        }

        if ( ! is_array($response))
        {
            $this->throwResponseConversionException();
        }

        return $response;
    }
1293492
public function handleAndResponseException(\Exception $ex)
    {

        $response = '';
        switch (true) {
            case $ex instanceof \Illuminate\Database\Eloquent\ModelNotFoundException:
                $response = $this->respondNotFound('Record not found');
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
                $response = $this->respondNotFound("Not found");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException:
                $response = $this->respondForbidden("Access denied");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
                $response = $this->respondBadRequest("Bad request");
                break;
            case $ex instanceof BadMethodCallException:
                $response = $this->respondBadRequest("Bad method Call");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException:
                $response = $this->respondForbidden("Method not found");
                break;
            case $ex instanceof \Illuminate\Database\QueryException:
                $response = $this->respondValidationError("Some thing went wrong with your query", [$ex->getMessage()]);
                break;
            case $ex instanceof \Illuminate\Http\Exceptions\HttpResponseException:
                $response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
                break;
            case $ex instanceof \Illuminate\Auth\AuthenticationException:
                $response = $this->respondUnauthorized("Unauthorized request");
                break;
            case $ex instanceof \Illuminate\Validation\ValidationException:
                $response = $this->respondValidationError("In valid request", [$ex->getMessage()]);
                break;
            case $ex instanceof NotAcceptableHttpException:
                $response = $this->respondUnauthorized("Unauthorized request");
                break;
            case $ex instanceof \Illuminate\Validation\UnauthorizedException:
                $response = $this->respondUnauthorized("Unauthorized request", [$ex->getMessage()]);
                break;
            case $ex instanceof \Exception:
                $response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
                break;
        }
        return $response;
    }
299940
public function toForm(){
        $returnValue = null;

        $interaction = $this->getAssociatedInteraction();
        if($interaction instanceof Interaction){
            $responseFormClass = '\\oat\\taoQtiItem\\controller\\QTIform\\response\\'.ucfirst(strtolower($interaction->getType())).'Interaction';
            if(class_exists($responseFormClass)){
                $formContainer = new $responseFormClass($this);
                $myForm = $formContainer->getForm();
                $returnValue = $myForm;
            }
        }else{
            throw new Exception('cannot find the parent interaction of the current response');
        }

        return $returnValue;
    }
1169454
protected function getErrorResponse()
    {
        if (Request::ajax()) {
            throw new AjaxException('Element not found');
        }

        return Response::make($this->controller->run('404')->getContent(), 404);
    }
837774
private function request_response()
    {
        // Must not block while reading
        stream_set_blocking($this->stream, false);
        
        $response = '';
        while (true) {
            $buffer = fgets($this->stream);
            $response .= $buffer;
            if (strstr($buffer, "\n")) {
                break;
            } else {
                usleep(1000);
            }
        }

        $data = '';
        if (!$response) {
            $this->close();
            $desc = $this->request_description();
            throw new ProtocolException("Unable to read response from server ({$desc})");
        } else if (null === ($data = json_decode(trim($response), true))) {
            $desc = $this->request_description();
            throw new ProtocolException("Unable to parse response from server ({$desc}): {$response}");
        } else if (!is_array($data)) {
            $desc = $this->request_description();
            throw new ProtocolException("Invalid response from server ({$desc}): ".json_encode($data));
        }

        if (isset($data['$error'])) {
            throw new ServerException((string)$data['$error']);
        }
        if (isset($data['$end'])) {
            $this->close();
        }

        return $data;
    }
1258478
public function processResourceRequestResponse(ResponseInterface $request)
    {
        $response = json_decode($request->getBody()->getContents());

        if (Response::HTTP_OK !== $request->getStatusCode() && Response::HTTP_CREATED !== $request->getStatusCode()) {
            return ExceptionHandler::handle(get_class($this), $response, $request->getStatusCode());
        }

        return (isset($response->data)) ? json_decode(json_encode($response->data), true) : json_decode(json_encode($response), true);
    }
1118111
public function render()
    {
        if ($this->isAjax()) {
            if ($this->isExport()) {

                if (!$this->getExportable()) {
                    throw new \Exception('Export not allowed');
                }

                $data = $this->processExport();
            } else {
                $data = $this->processGrid();
            }

            $json = json_encode($data);

            $response = new Response();
            $response->headers->set('Content-Type', 'application/json');
            $response->setContent($json);

            return $response;
        } else {
            if ($this->isExport()) {

                if (!$this->getExportable()) {
                    throw new \Exception('Export not allowed');
                }

                $exportFile = $this->getExportFileName();

                $response = new Response();
                $response->headers->set('Content-Type', 'text/csv');
                $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($exportFile) . '"');
                $response->setContent(file_get_contents($exportFile));

                return $response;
            } else {
                return new GridView($this, $this->container);
            }
        }
    }
972104
public function render($request, Exception $exception)
    {
        $exception = $this->prepareException($exception);

        if ($exception instanceof HttpResponseException) {
            return $exception->getResponse();
        } elseif ($exception instanceof AuthenticationException) {
            return $this->unauthenticated($request, $exception);
        } elseif ($exception instanceof ValidationException) {
            return $this->convertValidationExceptionToResponse($exception, $request);
        } elseif ($this->isHttpException($exception) && $this->customErrorHtmlTemplateExists($exception)) {
            return $this->prepareResponse($request, $exception);
        }

        $flattened = FlattenException::create($exception);

        $code = $flattened->getStatusCode();
        $headers = $flattened->getHeaders();
        $response = $this->getContent($exception, $code, $request);

        // If it's already a response, return that.
        if (!$response instanceof BaseResponse) {
            $response = new Response($this->getContent($exception, $code, $request), $code, $headers);
        }

        return $response;
    }
1177787
protected function genericResponse(Exception $exception): Response
    {
        $replacements = $this->prepareReplacements($exception);

        return new Response($replacements, $this->getHttpStatusCode($exception), $this->getHeaders($exception));
    }
833590
public function getResponseData(): Response
    {
        $connectionResponse = new ConnectionResponseImpl();
        $errorResponse = $this->streamSocket->read();
        if ($errorResponse !== null) {
            $this->getLogger()->error('Send error: ' . $errorResponse);
            $this->streamSocket->disconnect();
            $response = @unpack('Ccommand/Cstatus/Nidentifier', $errorResponse);
            if (!empty($response)) {
                $connectionResponse->setErrorResponse($response);
            } else {
                $connectionResponse->setErrorResponse(null);
            }
        }

        return $connectionResponse;
    }