Generate HTMLResponse from UserException

@param UserException $exception
@param array $values
@return \Orpheus\InputController\HTTPController\JSONHTTPResponse
6040
public static function generateFromUserException(UserException $exception, $values=array()) {
		$code = $exception->getCode();
		if( !$code ) {
			$code = HTTP_BAD_REQUEST;
		}
		if( $exception instanceof UserReportsException ) {
			/* @var $exception UserReportsException */
			$response = static::render($exception->getMessage(), $exception->getReports(), $exception->getDomain());
		} else {
			$response = static::render($exception->getMessage(), null, $exception->getDomain());
		}
		$response->setCode($code);
		return $response;
	}
1198917
public function handleTaskException(\Throwable $userException, $value)
    {
        try {
            if (!empty($this->routine) && $this->routine instanceof \Generator) {
                $this->routine->throw($userException);
            }
        } catch (\Throwable $noCatchUserException) {
            if ($this->stack->isEmpty()) {
                try {
                    throw $noCatchUserException;
                } catch (\Throwable $noCatch) {
                    if ($this->controller) {
                        $this->controller->onExceptionHandle($noCatch);
                    } else {
                        throw $noCatch;
                    }
                }

                return true;
            }

            $noCatchException = null;
            while (!$this->stack->isEmpty()) {
                $this->routine = $this->stack->pop();
                try {
                    $this->routine->throw($noCatchUserException);
                    break;
                } catch (\Throwable $e) {
                    if ($this->stack->isEmpty()) {
                        $noCatchException = $noCatchUserException;
                    }
                }
            }

            if ($this->stack->isEmpty() && $noCatchException !== null && $this->controller) {
                $this->controller->onExceptionHandle($noCatchException);
            }
        }

        return true;
    }
984648
protected function buildJsonResponseMiddleware(HttpException $exception) : MiddlewareInterface
    {
        return new class($this->responseFactory->createResponse(), $exception) implements MiddlewareInterface
        {
            protected $response;
            protected $exception;

            public function __construct(ResponseInterface $response, HttpException $exception)
            {
                $this->response  = $response;
                $this->exception = $exception;
            }

            public function process(
                ServerRequestInterface $request,
                RequestHandlerInterface $requestHandler
            ) : ResponseInterface {
                return $this->exception->buildJsonResponse($this->response);
            }
        };
    }
332624
public function processUserException(UserException $exception, $values=array()) {
		// This exception is a user one, we use an app page
		$response = $this->defaultResponse;
		return $response::generateFromUserException($exception, $values);
	}
855300
private function parseExceptionForErrorMessages(Exception $exception)
    {
        if (! $exception instanceof BadResponseException) {
            return new ApiException($exception->getMessage(), 0, $exception);
        }

        $response = $exception->getResponse();

        if (null === $response) {
            return new ApiException('Response is NULL.', 0, $exception);
        }

        Psr7\rewind_body($response);
        $responseBody = $response->getBody()->getContents();
        $decodedResponseBody = json_decode($responseBody, true);

        if (null !== $decodedResponseBody && isset($decodedResponseBody['error']['message']['value'])) {
            $errorMessage = $decodedResponseBody['error']['message']['value'];
        } else {
            $errorMessage = $responseBody;
        }

        $this->checkWhetherRateLimitHasBeenReached($response, $errorMessage);

        return new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage, $response->getStatusCode(), $exception);
    }
1135885
protected function renderException($exception)
    {
        $contentType = static::getContentType();
        $dataType = explode('/', $contentType);
        $dataType = isset($dataType[1]) ? $dataType[1] : 'text';

        switch ($dataType) {
            case 'json':
                $output = $this->getJsonMessage($exception);
                break;
                
            case 'xml':
                $output = $this->getXmlMessage($exception);
                break;
            
            case 'html':
                $output = $this->getHtmlMessage($exception);
                break;
                
            case 'text':
            default:
                $output = $this->getTextMessage($exception);
        }
        
        echo $output;
    }
196749
public static function sendException(\Exception $ex)
	{
		$class = get_class($ex);
		switch ($class) {
			case 'Smalldb\\StateMachine\\TransitionAccessException':
				$http_code = '403';
				break;
			case 'Smalldb\\StateMachine\\InstanceDoesNotExistException':
				$http_code = '404';
				break;
			default:
				$http_code = '500';
				break;
		}

		header("HTTP/1.0 $http_code Exception: $class");
		header('Content-Type: application/json; encoding=utf-8');
		static::writeException($ex);
	}
579523
public static function hipChatRespondedWithAnError(ClientException $exception)
    {
        return new static(sprintf(
            'HipChat responded with an error %s - %s',
            $exception->getResponse()->getStatusCode(),
            $exception->getResponse()->getBody()
        ));
    }
215871
protected function convertExceptionToResponse(Exception $e)
    {
        return SymfonyResponse::create(
            $this->renderExceptionContent($e),
            $this->isHttpException($e) ? $e->getStatusCode() : 500,
            $this->isHttpException($e) ? $e->getHeaders() : []
        );
    }
1224053
public static function telegramRespondedWithAnError(ClientException $exception)
    {
        $statusCode = $exception->getResponse()->getStatusCode();

        $description = 'no description given';

        if ($result = json_decode($exception->getResponse()->getBody())) {
            $description = $result->description ?: $description;
        }

        return new static("Telegram responded with an error `{$statusCode} - {$description}`");
    }
875306
public function createResponse($exception)
    {
        if (!$exception instanceof FlattenException) {
            $exception = FlattenException::create($exception);
        }

        return new Response($this->decorate($this->getContent($exception, $this->showAllExceptions), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders());
    }
452400
private function __prepareResponse($exception, $options = [])
    {
        $response = $this->_getController()->response;
        $code = $this->_code($exception);
        $response->getStatusCode($this->_code($exception));

        Configure::write('apiExceptionMessage', $exception->getMessage());

        $responseFormat = $this->_getController()->responseFormat;
        $responseData = [
            $responseFormat['statusKey'] => !empty($options['responseStatus']) ? $options['responseStatus'] : $responseFormat['statusNokText'],
            $responseFormat['resultKey'] => [
                $responseFormat['errorKey'] => ($code < 500) ? 'Not Found' : 'An Internal Error Has Occurred.',
            ],
        ];

        if ((isset($options['customMessage']) && $options['customMessage']) || Configure::read('ApiRequest.debug')) {
            $responseData[$responseFormat['resultKey']][$responseFormat['errorKey']] = $exception->getMessage();
        }

        if ('xml' === Configure::read('ApiRequest.responseType')) {
            $body = $response->getBody();
            $body->write(Xml::fromArray([Configure::read('ApiRequest.xmlResponseRootNode') => $responseData], 'tags')->asXML());
            $response->withBody($body);
        } else {
            $body = $response->getBody();
            $body->write(json_encode($responseData));
            $response->withBody($body);
        }

        $this->controller->response = $response;

        return $response;
    }
455858
public function fromException( Exception $exception )
    {
        return $this->generateResponse(
            xmlrpc_encode_request(
                null,
                array(
                    'faultCode' => $exception->getCode(),
                    'faultString' => $exception->getMessage()
                )
            )
        );
    }
329998
public function display(Exception $exception)
	{
		$status = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;

		return new Response(file_get_contents(__DIR__.'/resources/plain.html'), $status);
	}
1223414
public function createResponse(Exception $exception)
    {
        $data   = $this->createResponseData($exception);
        $status = $this->resolveResponseStatusCode($exception);

        return new JsonResponse($data, $status, [], JSON_PARTIAL_OUTPUT_ON_ERROR);
    }
581342
public function throwServiceExceptionFromRequestException(RequestException $exception)
    {
        $exceptionClass = ExceptionInterface::class;

        if ($exception->hasResponse() && $exception->getResponse()->hasHeader('X-WS-ErrorCode')) {
            $exceptionClass = $this->getServiceException($exception->getResponse()->getHeaderLine('X-WS-ErrorCode'));
        }
        if ($exceptionClass !== ExceptionInterface::class) {
            throw new $exceptionClass();
        }

        throw new ServerException('Unknown error occurred', 0, $exception);
    }
612050
public function convertExceptionToHtml($exception)
    {
        $flat = $this->getFlattenedException($exception);

        $handler = new SymfonyExceptionHandler();

        return $this->decorate($handler->getContent($flat), $handler->getStylesheet($flat), $flat);
    }