Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 3 |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
1 | <?php |
||
24 | 8 | public function onKernelException(ExceptionEvent $event): void |
|
25 | { |
||
26 | 8 | $exception = $event->getThrowable(); |
|
27 | |||
28 | 8 | if ($exception instanceof RequestDtoValidationException) { |
|
29 | 4 | $format = $event->getRequest()->getContentType() ?? 'json'; |
|
30 | |||
31 | 4 | if (!\in_array($format, ['json', 'xml'], true)) { |
|
32 | 2 | $format = 'json'; |
|
33 | } |
||
34 | |||
35 | 4 | $responseObject = (string) $this->serializer->serialize($exception, $format); |
|
36 | 4 | $event->setResponse( |
|
37 | 4 | new Response( |
|
38 | 4 | $responseObject, |
|
39 | 4 | $exception->getStatusCode(), |
|
40 | 4 | [...$exception->getHeaders(), 'Content-Type' => 'application/problem+' . $format] |
|
41 | ) |
||
46 |