Render an exception into a response.

@param  \Illuminate\Http\Request  $request
@param  \Exception  $e
@return \Illuminate\Http\Response
197210
public function render($request, Exception $e)
	{
		if ($this->isHttpException($e))
		{
			return $this->renderHttpException($e);
		}
		else
		{
			return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
		}
	}
1174966
public function render($request, Exception $e)
    {
        if ($this->isHttpException($e))
        {
            if ($request->segment(1) == config('expendable.admin_base_uri') && !config('app.debug'))
            {
                return app('Distilleries\Expendable\Http\Controllers\Backend\Base\ErrorController')->callAction("display", [$e, $e->getStatusCode()]);
            }
        }

        return parent::render($request, $e);
    }
206663
private function handleForBrowser(Exception $e)
    {
//        $request = request();
//        if ($e instanceof ModelNotFoundException) {
//            $e = new NotFoundHttpException($e->getMessage(), $e);
//        }
//        elseif ($e instanceof AuthorizationException) {
//            $e = new HttpException(403, $e->getMessage());
//        }
//
//        if ($e instanceof HttpResponseException) {
//            return $e->getResponse();
//        }
//        if ($e instanceof AuthenticationException) {
//            header('Location: ' . url('auth/login'));
//            exit;
//        }
//        else if ($e instanceof ValidationException) {
//            return $this->convertValidationExceptionToResponse($e, $request);
//        }
//        else if ($request->isAjax() || $request->wantsJson()) {
//            /** @var HttpException $e */
//            return response()->json($e->getMessage(), $this->isHttpException($e) ? $e->getStatusCode() : 400);
//        }

        $data = $this->convertException($e);

        // set error title and subtitle

        if ($e instanceof HttpException) {
            // set the HTTP Response Status Text as error title
            $data['title'] = http_status_text($data['status']);

            // set the Exception class and the HTTP Response Status Code as subtitle
            $data['subtitle'] = get_class($e) . ', Status Code ' . $data['status'];
        }
        else if ($e instanceof QueryException) {
            // set title
            $data['title'] = 'SQL Error';

            // set the Exception class and error codes as subtitle
            $data['subtitle'] = get_class($e) . ' (Exception code: ' . $data['code'] . ')';
            if ($data['ansiCode'] !== null) {
                $data['subtitle'] .= ', ANSI SQLSTATE Error Code: ' . $data['ansiCode'];
            }
            if ($data['driverCode'] !== null) {
                $data['subtitle'] .= ', Driver-specific Error Code: ' . $data['driverCode'];
            }
        }
        else {
            // set error title
            $data['title'] = 'Error';

            // // set the Exception class and the Exception code as subtitle
            $data['subtitle'] = get_class($e) . ' (Exception code: ' . $data['code'] . ')';
        }

        // render the source code

        if ($e instanceof QueryException) {
            // parse the sql line from the message if exists
            if (preg_match('/at line (\d)$/', $data['message'], $match)) {
                $sqlLine = $match[1];
            }
            else {
                $sqlLine = 0;
            }
            // set the SQL Statement as source
            $data['source'] = $this->renderSQL($data['sql'], $sqlLine);
        }
        else {
            // set the PHP Code as source
            $data['source'] = $this->renderPHP($data['file'], $data['line']);
        }

        // render the trace

        $data['trace'] = $this->renderTrace($data['trace']);

        // strip the filename

        $data['file'] = $this->stripFile($data['file']);

        // choose the template

        $view = config('app.debug') ? 'errors.debug' : 'errors.default';
        if (!config('app.debug') && view()->exists('errors.' . $data['status'])) {
            $view = 'errors.' . $data['status'];
        }

        // send the response

        $headers = ($e instanceof HttpException) ? $e->getHeaders() : [];

        return response()->view($view, $data, $data['status'], $headers)->send();
    }
252428
protected function prepareJsonResponse($request, Exception $e)
    {
        return new JsonResponse(
            $this->convertExceptionToArray($e),
            $this->isHttpException($e) ? $e->getStatusCode() : 500,
            $this->isHttpException($e) ? $e->getHeaders() : [],
            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
        );
    }
134386
public function render($request, $e)
	{
		if ($e instanceof \Error)
		{
			$e = new \Exception('Exception occured: ' . $e->getMessage() . "\nOriginal stack trace: " . 
				$e->getTraceAsString(), $e->getCode());
		}
		
		// If the request wants JSON (AJAX doesn't always want JSON)
		if ($request->wantsJson())
		{
			// Define the response
			$response = [
				'errors' => 'Sorry, something went wrong.'
			];

			// If the app is in debug mode
			if (config('app.debug'))
			{
				// Add the exception class name, message and stack trace to response
				$response['exception'] = get_class($e); // Reflection might be better here
				$response['message'] = $e->getMessage();
				$response['trace'] = $e->getTrace();
			}

			// Default response of 400
			$status = 400;

			// If this exception is an instance of HttpException
			if ($this->isHttpException($e))
			{
				// Grab the HTTP status code from the Exception
				$status = $e->getStatusCode();
			}

			// Return a JSON response with the response array and status code
			return response()->json($response, $status);
		}
		
		if ($this->isHttpException($e))
		{
			return $this->renderHttpException($e);
		}
		else
		{
			return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
		}
	}
582355
public function render($request, Exception $e)
    {
        if ($core = $this->getCoreIfBound()) {

            if ($core->bootChecker()->isCmsWebRequest()) {
                return $this->renderCmsWebException($request, $e);
            } elseif ($core->bootChecker()->isCmsApiRequest()) {
                return $this->renderCmsApiException($request, $e);
            }
        }

        return parent::render($request, $e);
    }
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);
    }
1003249
protected function renderHttpException(HttpException $e)
    {
        $status = $e->getStatusCode();

        if (view()->exists($this->getViewPath("errors.{$status}"))) {
            return response()->view($this->getViewPath("errors.{$status}"), ['exception' => $e], $status, $e->getHeaders());
        } elseif (view()->exists($this->getViewPath('errors.other'))) {
            return response()->view($this->getViewPath('errors.other'), ['exception' => $e], $status, $e->getHeaders());
        }

        return $this->convertExceptionToResponse($e);
    }
94296
public function render($request, Exception $e)
    {
        $errors = [
            'message' => $e->getMessage(),
            'trace' => collect($e->getTrace())->map(function ($item) {
                return [
                    'file' => array_get($item, 'file'),
                    'line' => array_get($item, 'line'),
                    'method' => array_get($item, 'function'),
                ];
            })->toArray(),
        ];
        $this->debug->setError($errors)->broadcast();

        return $this->exceptionHandler->render($request, $e);
    }
1128140
public function render($request, Exception $e)
    {
        if (str_is('api.*', $request->getHost())) {
            /** @TODO Really ugly hack to always return JSON for api */
            $request->headers->set('x-requested-with', 'XMLHttpRequest');
        }
        return parent::render($request, $e);
    }
202337
public function render($request, Exception $e)
    {
        $response = $this->exceptionHandler->render($request, $e);

        if ($this->shouldRenderException($response) === true) {
            $_SERVER = $request->server();
            $response->setContent(
                $this->debuggerManager->exceptionHandler($e)
            );
        }

        return $response;
    }
649844
public function render($request, Exception $e)
	{
		if ($this->isHttpException($e))
		{
			return $this->renderHttpException($e);
		}
		else
		{
			return parent::render($request, $e);
		}
	}
571886
public function routeError(\Exception $e)
    {
        if ($e instanceof NotFoundHttpException) {
            $responseContent = $this->twig()->render('Default\404.twig');
            $response = new Response($responseContent, 404);
        } else {
            $responseContent = $this->twig()->render('Default\500.twig', array('error' => $e->getMessage()));
            $response = new Response($responseContent, 500);
        }

        return $response;
    }
1119295
public function handle(\Exception $e) {

		try {
			ob_clean();
			$this->createResponse($e)->send();
		}
		
		catch(\Exception $e) {
			printf('Exception thrown when handling exception (%s: %s)', get_class($e), $e->getMessage());
			exit();
		}

	}
1365830
public function render(Exception $e)
    {
        if ($this->isConsole()) {
            $output = new StreamOutput(fopen('php://stdout', 'w'));
            $output->setVerbosity($this->debug ? OutputInterface::VERBOSITY_DEBUG : OutputInterface::VERBOSITY_NORMAL);

            return $this->renderForConsole($output, $e);
        } else {
            return $this->renderForBrowser($e);
        }
    }
556775
protected function renderHttpException(HttpException $e)
	{
		$status = $e->getStatusCode();

		if (view()->exists("errors.{$status}"))
		{
			return response()->view("errors.{$status}", [], $status);
		}
		else
		{
			return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
		}
	}
355424
protected function prepareResponse(Request $request, Exception $e)
    {
        if ($this->isHttpException($e)) {
            return $this->createResponse($this->renderHttpException($e, $request), $e);
        } else {
            return $this->createResponse($this->convertExceptionToResponse($e, $request), $e);
        }
    }