Map exception into a Nova response.

@param  \Symfony\Component\HttpFoundation\Response  $response
@param  \Exception  $e
@return \Nova\Http\Response
427977
protected function createResponse($response, Exception $e)
    {
        $response = new HttpResponse($response->getContent(), $response->getStatusCode(), $response->headers->all());

        return $response->withException($e);
    }
63597
public static function wrap(RequestException $e)
    {
        $response = $e->getResponse();

        if ($errors = self::errors($response)) {
            $class = self::exceptionClass($response, $errors[0]);
            $message = implode(', ', array_map('strval', $errors));
        } else {
            $class = self::exceptionClass($response);
            $message = $e->getMessage();
        }

        return new $class($message, $errors, $e->getRequest(), $response, $e);
    }
649844
public function render($request, Exception $e)
	{
		if ($this->isHttpException($e))
		{
			return $this->renderHttpException($e);
		}
		else
		{
			return parent::render($request, $e);
		}
	}
887840
public function render($request, Exception $e)
    {
        if (method_exists($e, 'render') && $response = $e->render($request)) {
            return Router::toResponse($request, $response);
        } elseif ($e instanceof Responsable) {
            return $e->toResponse($request);
        }

        $e = $this->prepareException($e);

        if ($e instanceof HttpResponseException) {
            return $e->getResponse();
        } elseif ($e instanceof AuthenticationException) {
            return $this->unauthenticated($request, $e);
        } elseif ($e instanceof ValidationException) {
            return $this->convertValidationExceptionToResponse($e, $request);
        }

        return $request->expectsJson()
                        ? $this->prepareJsonResponse($request, $e)
                        : $this->prepareResponse($request, $e);
    }
52461
protected function getErrorResponse(Exception $e)
    {
        switch (get_class($e)) {
            case ForbiddenException::class:
                $response = $this->forbidden(
                    new ErrorBag([new Error('Forbidden', $e->getMessage())])
                );
                break;
            default:
                $response = $this->errorResponse(
                    new ErrorBag([new Error('Bad Request', 'Request could not be served.')])
                );
        }

        return $response;
    }
966003
public function render($request, Exception $e)
	{
		if ($e instanceof HttpException) {
			$response = $e->response();
			
			if ($request->header('Origin')) {
				Cors::attachHeaders($response);
				$response->headers->set('Access-Control-Allow-Origin', $request->header('Origin'));
			}
			
			return $response;
		}
		
		return parent::render($request, $e);
	}
304231
protected function provideGeneralErrorResponse(\Exception $e): Response
    {
        $responder = $this->provideResponder();
        return $responder->error([
            'Message' => $e->getMessage(),
            'File' => $e->getFile(),
            'Line' => $e->getLine(),
        ]);
    }
1253013
public function handleException(\Exception $e): Response
    {
        if ($e instanceof NotFoundException) {
            $this->logger->info('404 Not Found: ' . $this->request->getRequestUri());
            $response = $this->provideNotFoundResponse();
        } elseif ($e instanceof MethodNotAllowedException) {
            $this->logger->notice('Method not allowed.', [
                'request_uri' => $this->request->getRequestUri(),
                'request_method' => $this->request->getRequestMethod(),
            ]);
            $response = $this->provideMethodNotAllowedResponse();
        } elseif ($e instanceof BadRequestException) {
            $this->logger->notice('Bad request.', [
                'request_uri' => $this->request->getRequestUri(),
                'request_method' => $this->request->getRequestMethod(),
            ]);
            $response = $this->provideBadRequestResponse();
        } else {
            $this->logger->error(sprintf('%s in %s:%d', $e->getMessage(), $e->getFile(), $e->getLine()));
            $response = $this->provideGeneralErrorResponse($e);
        }

        return $response;
    }
960364
protected function generateExceptionResponse(Exception $e){

        $e = FlattenException::create($e);
        $content = $this->decoreate($this->exceptionHandler->getContent($e), $this->exceptionHandler->getStylesheet($e), 'utf-8');

        return response($content, 500);
    }
638534
protected function deleteActionException(\Exception $e)
    {
        $this->handleException($e);

        return new RedirectResponse($this->admin->generateUrl('list'));
    }
1183347
public function render($request, Exception $e)
    {
        if ($this->isServiceException($e)) {
            $e->setRequest($request);
        } elseif ($e instanceof ValidationException) {
            $e = $this->convertValidationExceptionToEntityException($e);
        } else {
            $e = $this->convertExceptionToServiceException($e);
        }

        return $this->prepareJsonResponse($e);
    }
121050
public function render($request, Exception $e)
    {
        $packageResponse = [];
        $statusCode = 500;
        if (($message = $e->getMessage())) {
            $packageResponse['title'] = $message;
        }
        if ($e instanceof OAuthException) {
            $e = new AccessDeniedHttpException($e->getMessage());
        }
        if ($e instanceof HttpException) {
            $statusCode = $e->getStatusCode();
        }
        if ($e instanceof ErrorMessageBagException && $e->hasErrors()) {
            $packageResponse['errors'] = $e->getErrors();
        }

        return response()->json($packageResponse, $statusCode);
    }
347435
protected function getJsonFromResponse(Response $response)
    {
        $responseBody = $response->getBody();
        if ($response->getStatusCode() >= 400) {
            throw new Exception($responseBody);
        }
        $json = @json_decode($responseBody, true);
        if ($json === null) {
            throw new Exception('Failed to decode CommunityTranslation response');
        }

        return $json;
    }
382852
protected function renderApplication(Exception $e)
    {
        $response = $this->getExceptionHandler()->render($this->app['request'], $e);
        $response->send();
    }
921208
private function getJsonException(\Exception $e)
    {
        $file = Path::makeRelative($e->getFile(), $this->app['path_resolver']->resolve('root'));

        $error = [
            'error' => [
                'type'    => get_class($e),
                'file'    => $file,
                'line'    => $e->getLine(),
                'message' => $e->getMessage(),
            ],
        ];

        return new JsonResponse($error, Response::HTTP_INTERNAL_SERVER_ERROR);
    }
1183736
protected function processResponse(Response $response)
    {
        if ($response->hasErrors()) {
            throw new \Exception($this->getErrorMessage($response));
        }

        return is_array($response->body) ? $response->body['data'] : $response->body->data;
    }
657187
public function render(Request $request, Exception $e)
    {
        $e = $this->prepareException($e);

        if ($e instanceof HttpResponseException) {
            return $e->getResponse();
        } else if ($e instanceof AuthenticationException) {
            return $this->unauthenticated($request, $e);
        } else if ($e instanceof ValidationException) {
            return $this->convertValidationExceptionToResponse($e, $request);
        }

        return $this->prepareResponse($request, $e);
    }