Skip to content

Commit 6ebfd94

Browse files
committed
handle StopFormatListenerException in the ExceptionController
1 parent a984147 commit 6ebfd94

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Controller/ExceptionController.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\RestBundle\Controller;
1313

14+
use FOS\RestBundle\Util\StopFormatListenerException;
1415
use FOS\RestBundle\View\ExceptionWrapperHandlerInterface;
1516
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
1617
use Symfony\Component\HttpKernel\Exception\FlattenException as HttpFlattenException;
@@ -209,9 +210,13 @@ protected function getStatusCode($exception)
209210
*/
210211
protected function getFormat(Request $request, $format)
211212
{
212-
$formatNegotiator = $this->container->get('fos_rest.format_negotiator');
213-
$format = $formatNegotiator->getBestFormat($request) ?: $format;
214-
$request->attributes->set('_format', $format);
213+
try {
214+
$formatNegotiator = $this->container->get('fos_rest.format_negotiator');
215+
$format = $formatNegotiator->getBestFormat($request) ?: $format;
216+
$request->attributes->set('_format', $format);
217+
} catch (StopFormatListenerException $e) {
218+
$format = $request->getRequestFormat();
219+
}
215220

216221
return $format;
217222
}

0 commit comments

Comments
 (0)