create response objecto to exception message

@param Exception $e
@return mixed
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);
    }
791935
private function generateExceptionResponse($request, Exception $e)
    {
        $formatters = $this->config['formatters'];

        // :: notation will otherwise not work for PHP <= 5.6
        $responseFactoryClass = $this->config['response_factory'];

        // Allow users to have a base formatter for every response.
        $response = $responseFactoryClass::make($e);

        foreach($formatters as $exceptionType => $formatter) {
            if (!($e instanceof $exceptionType)) {
                continue;
            }

            if (
                !class_exists($formatter) ||
                !(new ReflectionClass($formatter))->isSubclassOf(new ReflectionClass(BaseFormatter::class))
            ) {
                throw new InvalidArgumentException(
                    sprintf(
                        "%s is not a valid formatter class.",
                        $formatter
                    )
                );
            }

            $formatterInstance = new $formatter($this->config, $this->debug);
            $formatterInstance->format($response, $e, $this->reportResponses);

            break;
        }

        return $response;
    }
795648
protected function getErrorResponse(Exception $e, ErrorBag $errorBag)
    {
        switch (get_class($e)) {
            case ForbiddenException::class:
                $response = $this->forbidden($this->errorBag);
                break;
            case DataException::class:
                $response = $this->unprocessableEntity($errorBag);
                break;

            default:
                $response = $this->errorResponse(
                    new ErrorBag([new Error('Bad Request', 'Request could not be served.')])
                );
        }

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

		return $response->withException( $e );
	}
1237517
protected function handleError(\Exception $e) {
		$kernel = $this->getDefaultKernel();
		$application = $this->getDefaultApplication($kernel);

		$kernel->getResponse()->addValue("error", $e->getMessage());
		$this->logger->logError($e->getMessage());

		return $application;
	}
1284129
protected function doException(\Exception $e)
    {
        $command = new DefaultConsoleCommand();
        $command->data = '"Error #' . $e->getCode() . ' - ' . $e->getMessage() . '"';
        $command->execute();

        $response = (new ResponseInjector)->build();
        $response = $response->withHeader('status', (string)(int)$command->result); // TODO: hack for select cli stream

        $stream = $response->getBody();
        $stream->write($command->message);

        return $response->withBody($stream);
    }
479349
public function formatException(\Exception $e) {
        $xml = new XMLWriter();
        $xml->openMemory();
        $xml->writeElement('class', get_class($e));
        $xml->writeElement('message', htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8'));
        $xml->writeElement('file', htmlspecialchars($e->getFile(), ENT_QUOTES, 'UTF-8'));
        $xml->writeElement('line', $e->getLine());
        $xml->writeElement('trace', htmlspecialchars($e->getTraceAsString(), ENT_QUOTES, 'UTF-8'));

        return $xml->outputMemory();
    }
570962
protected function genericResponse(Exception $exception)
    {
        $replacements = $this->prepareReplacements($exception);

        $response = $this->newResponseArray();

        array_walk_recursive($response, function (&$value, $key) use ($exception, $replacements) {
            if (starts_with($value, ':') && isset($replacements[$value])) {
                $value = $replacements[$value];
            }
        });

        $response = $this->recursivelyRemoveEmptyReplacements($response);

        return new Response($response, $this->getExceptionStatusCode($exception), $this->getHeaders($exception));
    }
572493
protected function doException(\Exception $e)
    {
        $output = (new ResponseInjector)->build();

        $errorController = (new Injector)->param('errorController');
        $errorAction = (new Injector)->param('errorAction');

        if (!$errorController || !$errorAction) { // render SAPI error not configured
            $stream = $output->getBody();
            $stream->write('Option `errorController` or `errorAction` not configured');

            return $output->withBody($stream);
        }

        // Render SAPI error
        $body = (new RequestInjector)->build()->getParsedBody();
        $body['error'] = $e;

        $request = (new RequestInjector)->build()->withParsedBody($body);
        (new Injector)->addRequirement('request', $request);

        $controller = $errorController;

        /** @var \Micro\Mvc\Controllers\IController $result */
        $result = new $controller(false);
        $result = $result->action($errorAction);

        if ($result instanceof ResponseInterface) {
            return $result;
        }

        $stream = $output->getBody();
        $stream->write((string)$result);

        return $output->withBody($stream);
    }
641807
public function createExceptionResponse(\Exception $exception)
    {
        $responseData = [
            'code' => $exception->getCode(),
            'type' => static::TYPE_ERROR,
            'message' => $exception->getMessage(),
        ];

        if ($exception instanceof ValidationException) {
            $exception = new \KodiCMS\API\Exceptions\ValidationException($exception->validator);
        }

        if ($exception instanceof Exception or method_exists($exception, 'responseArray')) {
            $responseData = array_merge($responseData, $exception->responseArray());
        } else if ($exception instanceof ModelNotFoundException) {
            $responseData['code'] = static::ERROR_PAGE_NOT_FOUND;
        } else if ($exception instanceof MassAssignmentException) {
            $responseData['code']  = static::ERROR_MISSING_ASSIGMENT;
            $responseData['field'] = $exception->getMessage();
        }

        if ($this->debug) {
            $responseData['file'] = $exception->getFile();
            $responseData['line'] = $exception->getLine();
        }

        return $this->createResponse($responseData, 500);
    }
992992
protected function handleGenericException(Exception $e)
    {
        // Get the status code and build the message.
        $statusCode = 500;
        $message = $e->getMessage();

        return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
    }
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();
		}

	}
395496
public function getResponseException($e)
    {
        $e       = $this->decorateExceptionWithDebugTrace($e);
        $message = $this->formatExceptionMessage($e);

        $this->sendHeaderIfEnabled();

        return $this->apiRenderer->renderException($message, $e);
    }
831336
protected function buildFromException(\Exception $e)
    {
        $rs = [
            'return' => false, 'status' => 500,
            'exception' => [
                'msg'  => $e->getMessage(),
                'code' => $e->getCode(),
                'file' => $e->getFile(),
                'line' => $e->getLine(),
            ],
        ];

        return $this->packResult($rs);
    }
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());
    }
267048
public function addException(\Exception $e)
    {
        if ($this->initialized && $this->enabled()) {
            $this->debugbar['exceptions']->addException($e);
        }

        return $this;
    }
1152111
protected function prepareResponse($request, Exception $e)
    {
        if (! $this->isHttpException($e) && config('app.debug')) {
            return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
        }

        if (! $this->isHttpException($e)) {
            $e = new HttpException(500, $e->getMessage());
        }

        return $this->toIlluminateResponse(
            $this->renderHttpException($e), $e
        );
    }