Get a response from an exception.
@param  \Exception|\Throwable $e
@return Response
486490
protected function getExceptionResponse($e) {
		while(ob_get_level() > $this->startObLevel)
			ob_end_clean();

		$this->errorHandler->exceptionHandler($e);

		$trace = $this->errorHandler->getBacktraceFromException($e);

		if($e instanceof \Asgard\Debug\PSRException)
			$msg = $e->getMessage();
		elseif($e instanceof \ErrorException)
			$msg = 'PHP ('.$this->errorHandler->getPHPError($e->getCode()).'): '.$e->getMessage();
		else
			$msg = get_class($e).': '.$e->getMessage();

		$result = '<b>Message</b><br>'."\n"
			. $msg."<hr>\n"
			. \Asgard\Debug\Debug::getReport($trace);

		$response = new \Asgard\Http\Response(500);
		if($this->debug)
			return $response->setHeader('Content-Type', 'text/html')->setContent($result);
		else {
			$msg = isset($this->translator) ? $this->translator->trans('<h1>Error</h1>Oops, something went wrong.'):'<h1>Error</h1>Oops, something went wrong.';
			return $response->setHeader('Content-Type', 'text/html')->setContent($msg);
		}
	}
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;
    }
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());
    }
1037989
public function onKernelException(GetResponseForExceptionEvent $e)
    {
        if (!$this->enabled) return;

        $req = $e->getRequest();
        $cfg = $req->attributes->get('_ac_web_service');

        //notify of generic API error, return early if a response gets set
        $e->getDispatcher()->dispatch(self::API_EXCEPTION, $e);
        if ($e->getResponse()) {
            return;
        }

        //handle exception body format
        $exception = $e->getException();
        $exceptionClass = get_class($exception);

        //preserve specific http exception codes and messages, otherwise it's 500
        $realHttpErrorCode = $outgoingHttpStatusCode = 500;
        $errorMessage = "Internal Server Error";
        if ($exception instanceof ServiceException) {
            $errorData = $exception->getData();
        }
        if ($exception instanceof HttpException) {
            $realHttpErrorCode = $outgoingHttpStatusCode = $exception->getStatusCode();
            $errorMessage = ($exception->getMessage()) ? $exception->getMessage() : Response::$statusTexts[$realHttpErrorCode];
        } elseif (isset($cfg['http_exception_map'][$exceptionClass])) {
            //check exception map for overrides
            $map = $cfg['http_exception_map'];
            $realHttpErrorCode = $outgoingHttpStatusCode = $map[$exceptionClass]['code'];
            $errorMessage =
                (isset($map[$exceptionClass]['message']))
                ? $map[$exceptionClass]['message']
                : Response::$statusTexts[$realHttpErrorCode];
        }

        //set generic error data
        if (!isset ($errorData)) {
            $errorData = [];
        }
        $errorData['response'] = [
            'code' => $realHttpErrorCode,
            'message' => $errorMessage,
        ];

        //inject exception data if configured to do so
        if ($cfg['include_exception_data']) {
            $errorData['exception'] = array(
                'class' => get_class($exception),
                'message' => $exception->getMessage(),
                'code' => $exception->getCode(),
                'file' => $exception->getFile(),
                'line' => $exception->getLine(),
                'trace' => explode("\n", ImprovedStackTrace::getTrace($exception)),
            );
        }

        //serialize error content into requested format, if format is not supported by the serializer, do json
        //TODO: consider support for exception template formats
        $format = isset($cfg['http_response_format']) ? $cfg['http_response_format'] : $cfg['default_response_format'];
        $format = (in_array($format, $this->serializableFormats)) ? $format : 'json';
        $content = $this->container->get('serializer')->serialize($errorData, $format);

        //check for code suppression
        if ($cfg['suppress_response_codes']) {
            $outgoingHttpStatusCode = 200;
        }

        //log the exception
        $logLevel = $realHttpErrorCode >= 500 ? 'error' : 'warning';
        $logMessage =
            "Caught exception (mapped to code $realHttpErrorCode), " .
            "response to client becomes HTTP $outgoingHttpStatusCode $errorMessage\n" .
            ImprovedStackTrace::getTrace($exception) . "\n---";
        $this->logger->log($logLevel, $logMessage);

        $headers = array_merge($cfg['additional_headers'], $this->formatHeaders[$format]);

        //set response
        $e->setResponse(new Response($content, $outgoingHttpStatusCode, $headers));
    }
741941
protected function getErrorReason(\Throwable $e)
    {
        $reason = null;
        switch (true) {
            /* beStrictAboutOutputDuringTests="true" */
            case $e instanceof OutputError:
                $reason = 'No output during test';
                break;
            /* checkForUnintentionallyCoveredCode="true" */
            case $e instanceof UnintentionallyCoveredCodeError:
                $reason = 'Executed code must be defined with @covers and @uses annotations';
                break;
            default:
                if (preg_match('#\-\-\- Global variables before the test#', $e->getMessage())) {
                    /* beStrictAboutChangesToGlobalState="true" (no specific exception) for globals */
                    $reason = 'No global variable manipulation during test';
                } elseif (preg_match('#\-\-\- Static attributes before the test#', $e->getMessage())) {
                    /* beStrictAboutChangesToGlobalState="true" (no specific exception) for static var */
                    /* Only when beStrictAboutChangesToGlobalState="true" */
                    $reason = 'No static attribute manipulation during test';
                } elseif (preg_match('#This test did not perform any assertions#', $e->getMessage())) {
                    /* beStrictAboutTestsThatDoNotTestAnything="true" (no specific exception) */
                    $reason = 'No test that do not test anything';
                } elseif (preg_match('#Trying to @cover or @use not existing #', $e->getMessage())) {
                    /* forceCoversAnnotation="true" (no specific exception) */
                    $reason = 'Only executed code must be defined with @covers and @uses annotations';
                }
                break;
        }
        return $reason;
    }
993941
public function throwableToResponse(\Throwable $e) : ResponseInterface
    {
        $response = $this->responseFactory->createResponse();
        
        if ($e instanceof HttpException) {
            $statusCode = $e->getStatusCode();
        } else {
            $statusCode = $e->getCode() != 0 ? $e->getCode() : 500;
        }
        
        $response = $response->withStatus($statusCode);
        
        try {
            $html = $this->getHtmlFromTemplate($e);
        } catch (\Throwable $e) {
            $html = $this->getHtmlForException($e);
        }
        
        $response->getBody()->write($html);
        
        return $response;
    }
959018
protected function statusCodeHandling($e)
    {
        $response =(object)array(
            "Status" => $e->getResponse()->getStatusCode(),
            "Error" => json_decode($e->getResponse()->getBody(true)->getContents())
        );
        return $response;
    }
225836
public function formatException(\Exception $e) {
        $entry = array();

        $entry['class'] = get_class($e);
        $entry['message'] = $e->getMessage();
        $entry['file'] = $e->getFile();
        $entry['line'] = $e->getLine();
        $entry['trace'] = $e->getTraceAsString();

        return $entry;
    }
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());
    }
634859
public function onExceptionHandle(\Throwable $e)
    {
        try {
            if ($e->getPrevious()) {
                $ce = $e->getPrevious();
                $errMsg = dump($ce, false, true);
            } else {
                $errMsg = dump($e, false, true);
                $ce = $e;
            }

            $this->getContext()->getLog()->error($errMsg);
            $this->outputJson(parent::$stdClass, 'Internal Server Error', 500);
        } catch (\Throwable $ne) {
            getInstance()->log->error('previous exception ' . dump($ce, false, true));
            getInstance()->log->error('handle exception ' . dump($ne, false, true));
        }
    }
18198
protected function handleHttpException(Exception $e)
    {
        $statusCode = $e->getStatusCode();

        // if there is no exception message just get the standard HTTP text.
        if (empty($e->getMessage())) {
            $message = Response::$statusTexts[$statusCode];
        } else {
            $message = $e->getMessage();
        }

        return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
    }
1289326
private function handleException(\Exception $ex)
    {
        if (null !== $response = $this->handleInternalException($ex)) {
            $this->logException($ex);

            return $response;
        }

        try {
            $this->exceptionHandler->handle($ex);
        } catch (\Exception $ex) {
            if (null !== $response = $this->handleInternalException($ex)) {
                return $response;
            }
        }

        throw $ex;
    }
1073310
protected function handleValidationException(Exception $e)
    {
        // Get the status code and build the message.
        $statusCode = 422;
        $message = $e->getMessage();
        $errorData = $e->getResponse()->getData();

        return $this->generateResponse('errors', $errorData, $statusCode, Status::FAIL, $message);
    }
1093928
public function getExceptionBacktrace(\Throwable $e)
    {
        $backtrace[] = [
            'line' => $e->getLine(),
            'file' => $e->getFile(),
            'code' => $e->getCode(),
            'message' => $e->getMessage(),
        ];

        if ($e->getPrevious()) {
            return array_merge(
                $backtrace,
                $this->getExceptionBacktrace($e->getPrevious())
            );
        }

        return $backtrace;
    }
663631
protected function toIlluminateResponse($response, Exception $e)
    {
        $response = new Response($response->getContent(), $response->getStatusCode(), $response->headers->all());

        $response->exception = $e;

        return $response;
    }
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);
        }
    }
819987
protected function formatException(\Exception $e)
	{
		if ($this->debug)
		{
			$location = $e->getMessage().' in '.$e->getFile().':'.$e->getLine();

			return 'Error in exception handler: '.$location;
		}

		return 'Error in exception handler.';
	}