Skip to content

Commit

Permalink
[HttpFoundation] Do not set the default Content-Type based on the Acc…
Browse files Browse the repository at this point in the history
…ept header
  • Loading branch information
yceruto authored and nicolas-grekas committed Mar 30, 2020
1 parent e818d86 commit 7e9828f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ErrorRenderer/SerializerErrorRenderer.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\ErrorHandler\ErrorRenderer;

use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -30,6 +31,7 @@ class SerializerErrorRenderer implements ErrorRendererInterface

/**
* @param string|callable(FlattenException) $format The format as a string or a callable that should return it
* formats not supported by Request::getMimeTypes() should be given as mime types
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
*/
public function __construct(SerializerInterface $serializer, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
Expand Down Expand Up @@ -57,11 +59,16 @@ public function render(\Throwable $exception): FlattenException

try {
$format = \is_string($this->format) ? $this->format : ($this->format)($flattenException);
$headers = [
'Content-Type' => Request::getMimeTypes($format)[0] ?? $format,
'Vary' => 'Accept',
];

return $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
'exception' => $exception,
'debug' => \is_bool($this->debug) ? $this->debug : ($this->debug)($exception),
]));
]))
->setHeaders($flattenException->getHeaders() + $headers);
} catch (NotEncodableValueException $e) {
return $this->fallbackErrorRenderer->render($exception);
}
Expand Down

0 comments on commit 7e9828f

Please sign in to comment.