Skip to content

Commit 016f173

Browse files
[ErrorHandler] Fix sending Vary header with SerializerErrorRenderer
1 parent 56a94aa commit 016f173

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

ErrorRenderer/SerializerErrorRenderer.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(SerializerInterface $serializer, $format, ErrorRende
5555
*/
5656
public function render(\Throwable $exception): FlattenException
5757
{
58-
$headers = [];
58+
$headers = ['Vary' => 'Accept'];
5959
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
6060
if ($debug) {
6161
$headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
@@ -66,19 +66,17 @@ public function render(\Throwable $exception): FlattenException
6666

6767
try {
6868
$format = \is_string($this->format) ? $this->format : ($this->format)($flattenException);
69-
$headers = [
70-
'Content-Type' => Request::getMimeTypes($format)[0] ?? $format,
71-
'Vary' => 'Accept',
72-
];
69+
$headers['Content-Type'] = Request::getMimeTypes($format)[0] ?? $format;
7370

74-
return $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
71+
$flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
7572
'exception' => $exception,
7673
'debug' => $debug,
77-
]))
78-
->setHeaders($flattenException->getHeaders() + $headers);
74+
]));
7975
} catch (NotEncodableValueException $e) {
80-
return $this->fallbackErrorRenderer->render($exception);
76+
$flattenException = $this->fallbackErrorRenderer->render($exception);
8177
}
78+
79+
return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
8280
}
8381

8482
public static function getPreferredFormat(RequestStack $requestStack): \Closure

0 commit comments

Comments
 (0)