@param \Exception              $e
@param ServiceRequestInterface $request

@return array|mixed|string
@throws \DreamFactory\Core\Exceptions\NotImplementedException
332912
public static function sendException(\Exception $e, ServiceRequestInterface $request = null)
    {
        $response = static::exceptionToServiceResponse($e);

        return ResponseFactory::sendResponse($response, $request);
    }
397084
protected function convertExceptionToResponse(Exception $e)
    {
        $e = FlattenException::create($e);

        $handler = new SymfonyExceptionHandler(config('app.debug'));

        $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e));

        return SymfonyResponse::create($decorated, $e->getStatusCode(), $e->getHeaders());
    }
98751
public function exception($e) {
        $type = "system";
        if (isset($_GET['type'])) {
            $type = $_GET['type'];
        }
        switch ($type) {
        case 'dapi':
        case 'api':
            $this->exception[] = $e;
            break;
        case 'page':
        default:
            require __DIR__ . '/exception.php';
            break;
        }
    }
1033710
public function render( $request, Exception $e )
	{
		$transformed = $this->getTransformed( $e );

		$response = method_exists( $e, 'getResponse' ) ? $e->getResponse() : null;

		if ( !$response instanceof Response )
			try
			{
				$response = $this->getResponse( $request, $e, $transformed );
			}
			catch ( Exception $e )
			{
				$this->report( $e );
				$response = new Response( 'Internal server error.', 500 );
			}

		return $this->toHttpResponse( $response, $transformed );
	}
835076
protected function convertExceptionToServiceException(Exception $e): ServiceException
    {
        $exception = get_class($e);
        $conversion = $this->container['config']->get('exception.conversion', []);

        if (isset($conversion[$exception])) {
            return new $conversion[$exception]($e->getMessage(), $e->getCode(), $e);
        } /*else if (in_array($exception, $conversion, true)) {
            return new ServiceException($e->getMessage(), 400, $e);
        }*/ else {
            $statusCode = method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 400;

            return new ServiceException($e->getMessage(), $statusCode, $e);
        }
    }
649844
public function render($request, Exception $e)
	{
		if ($this->isHttpException($e))
		{
			return $this->renderHttpException($e);
		}
		else
		{
			return parent::render($request, $e);
		}
	}
787510
protected function renderException(Request $request, Exception $e)
    {
        return $this->app['Nano7\Foundation\Contracts\Exception\ExceptionHandler']->render($request, $e);
    }
772740
private function convertException(Exception $e)
    {
        $data = [];
        $data['message']  = $e->getMessage();
        $data['code']     = $e->getCode();
        $data['trace']    = $this->filterTrace($e->getTrace());
        $data['status']   = Response::HTTP_INTERNAL_SERVER_ERROR;

        // determine the relevant file
        $firstTraceEntry = !empty($data['trace']) ? reset($data['trace']) : null;
        if ($firstTraceEntry !== null && isset($firstTraceEntry['file']) && isset($firstTraceEntry['line'])) {
            $data['file'] = $firstTraceEntry['file'];
            $data['line'] = $firstTraceEntry['line'];
        }
        else {
            $data['file'] = $e->getFile();
            $data['line'] = $e->getLine();
        }

        if ($e instanceof HttpException) {
            $data['status'] = $e->getStatusCode() ?: Response::HTTP_INTERNAL_SERVER_ERROR;
        }
        else if ($e instanceof QueryException) {
            $data['ansiCode']   = isset($e->errorInfo[0]) ? $e->errorInfo[0] : null;
            $data['driverCode'] = isset($e->errorInfo[1]) ? $e->errorInfo[1] : null;
            if (!empty($e->errorInfo[2])) {
                $data['message'] = $e->errorInfo[2];
            }
            $data['sql'] = $e->getDump();
        }

        return $data;
    }
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;
    }
307869
protected function handle404s($request, BaseException $e)
    {
        // Check for right exception
        if (!is_a($e, ModelNotFoundException::class) && !is_a($e, NotFoundHttpException::class)) {
            return;
        }

        // Check for a valid redirect
        if ($rule = RedirectRule::matchUsingRequest()->first()) {
            return redirect($rule->to, $rule->code);
        }

        // Return header only on AJAX
        if ($request->ajax()) {
            return response(null, 404);
        }
    }
860943
protected function prepareJsonResponse($request, \Exception $e)
    {
        $headers = $this->isHttpException($e) ? $e->getHeaders() : [];

        return JsonResponse::create(
            $this->message,
            $this->statusCode ?: 500,
            $headers
        );
    }
949703
public function render($request, Exception $e)
    {
        if ($e instanceof HttpResponseException) {
            return $e->getResponse();
        }

        if ($this->isHttpException($e)) {
            return $this->toIlluminateResponse($this->renderHttpException($e), $e);
        } else {
            return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
        }
    }
1300432
public function render($request, Exception $e)
    {
        if ($e instanceof HttpResponseException) {
            return $e->getResponse();
        } elseif ($e instanceof ModelNotFoundException) {
            $e = new NotFoundHttpException($e->getMessage(), $e);
        } elseif ($e instanceof AuthorizationException) {
            $e = new HttpException(403, $e->getMessage());
        } elseif ($e instanceof ValidationException && $e->getResponse()) {
            return $e->getResponse();
        }

        $fe = FlattenException::create($e);

        $handler = new SymfonyExceptionHandler(\env('APP_DEBUG', false));

        $decorated = $this->decorate($handler->getContent($fe), $handler->getStylesheet($fe));

        $response = new Response($decorated, $fe->getStatusCode(), $fe->getHeaders());

        $response->exception = $e;

        return $response;
    }
930618
protected function convertExceptionToResponse(Exception $e, Request $request)
    {
        $debug = Config::get('app.debug');

        //
        $e = FlattenException::create($e);

        $handler = new SymfonyExceptionHandler($debug);

        return SymfonyResponse::create($handler->getHtml($e), $e->getStatusCode(), $e->getHeaders());
    }
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);
    }
514107
protected function handleException(\Exception $e, $request, $type)
    {
        $event = new FilterExceptionEvent($this, $request, $type);
        $event->setException($e);

        $this->getDispatcher()->dispatch(KernelEvents::EXCEPTION, $event);

        $e = $event->getException();

        if ( ! $event->hasResponse()) {
            throw $e;
        }

        $response = $event->getResponse();

        if ( ! $response->isClientError() && ! $response->isServerError() && ! $response->isRedirect()) {
            if ($e instanceof HttpExceptionInterface) {
                $response->setStatusCode($e->getStatusCode());
                $response->headers->add($e->getHeaders());
            } else {
                $response->setStatusCode(500);
            }
        }

        try {
            return $this->filterResponse($response, $request, $type);
        } catch (\Exception $e) {
            return $response;
        }
    }
1161521
protected function removeErroredRequest(RequestInterface $request, \Exception $e = null, $buffer = true)
    {
        if ($buffer) {
            $this->exceptions[] = array('request' => $request, 'exception' => $e);
        }

        $this->remove($request);
        $this->dispatch(self::MULTI_EXCEPTION, array('exception' => $e, 'all_exceptions' => $this->exceptions));
    }