Conditions | 3 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
21 | public function onKernelException(GetResponseForExceptionEvent $event) |
||
22 | { |
||
23 | $throwedException = $event->getException(); |
||
24 | |||
25 | $errorBody = [ |
||
26 | 'code' => $throwedException->getCode(), |
||
27 | 'message' => $throwedException->getMessage(), |
||
28 | ]; |
||
29 | |||
30 | if ($throwedException instanceof ValidatorException) { |
||
31 | $errorBody['message'] = 'Invalid data has been sent'; |
||
32 | } |
||
33 | |||
34 | if ($this->isKernelDebug) { |
||
35 | $errorBody['exception'] = [ |
||
36 | 'class' => get_class($throwedException) |
||
37 | ]; |
||
38 | $errorBody['trace'] = $throwedException->getTrace(); |
||
39 | } |
||
40 | |||
41 | $event->setResponse(new JsonResponse(['success' => false, 'error' => $errorBody])); |
||
42 | } |
||
44 |