Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5d76d7

Browse files
[ErrorHandler] Fix sending Vary header with SerializerErrorRenderer
1 parent 46b6994 commit a5d76d7

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Symfony/Component/ErrorHandler/ErrorRenderer/SerializerErrorRenderer.php

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

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

74-
return $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
72+
$flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
7573
'exception' => $exception,
7674
'debug' => $debug,
77-
]))
78-
->setHeaders($flattenException->getHeaders() + $headers);
75+
]));
7976
} catch (NotEncodableValueException $e) {
80-
return $this->fallbackErrorRenderer->render($exception);
77+
$flattenException = $this->fallbackErrorRenderer->render($exception);
8178
}
79+
80+
return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
8281
}
8382

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

0 commit comments

Comments
 (0)