diff --git a/Slim/Handlers/Error.php b/Slim/Handlers/Error.php index 3b1962aa9..cfced9905 100644 --- a/Slim/Handlers/Error.php +++ b/Slim/Handlers/Error.php @@ -23,6 +23,18 @@ class Error { protected $displayErrorDetails; + /** + * Known handled content types + * + * @var array + */ + protected $knownContentTypes = [ + 'application/json', + 'application/xml', + 'text/xml', + 'text/html', + ]; + /** * Constructor * @@ -44,7 +56,7 @@ public function __construct($displayErrorDetails = false) */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Exception $exception) { - $contentType = $this->determineContentType($request->getHeaderLine('Accept')); + $contentType = $this->determineContentType($request); switch ($contentType) { case 'application/json': $output = $this->renderJsonErrorMessage($exception); @@ -56,8 +68,6 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res break; case 'text/html': - default: - $contentType = 'text/html'; $output = $this->renderHtmlErrorMessage($exception); break; } @@ -97,8 +107,8 @@ private function renderHtmlErrorMessage(Exception $exception) $output = sprintf( "
" . "