File tree Expand file tree Collapse file tree 2 files changed +12
-13
lines changed Expand file tree Collapse file tree 2 files changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)
26
26
$ response = null ;
27
27
28
28
if (null !== $ resolvedHttpCode ) {
29
- $ response =new JsonResponse (['errors ' => ['message ' => $ exception ->getMessage ()]], $ resolvedHttpCode );
29
+ $ response = new JsonResponse (['errors ' => ['message ' => $ exception ->getMessage ()]], $ resolvedHttpCode );
30
30
}
31
31
32
32
if ($ exception instanceof InvalidCommandException) {
@@ -56,12 +56,9 @@ public function onKernelException(GetResponseForExceptionEvent $event)
56
56
$ response = new JsonResponse (['errors ' => $ violationsPayload ], 400 );
57
57
}
58
58
59
- if (null = == $ response ) {
60
- // If no support found, we let JsonExceptionController show it
61
- throw $ exception ;
59
+ if (null ! == $ response ) {
60
+ // Will stop the propagation according to symfony doc
61
+ $ event -> setResponse ( $ response ) ;
62
62
}
63
-
64
- // Will stop the propagation according to symfony doc
65
- $ event ->setResponse ($ response );
66
63
}
67
64
}
Original file line number Diff line number Diff line change 6
6
7
7
class JsonExceptionHandler extends atoum \test
8
8
{
9
- public function test_uncaught_exception_should_be_thrown ()
9
+ public function test_uncaught_exception_should_not_alter_event_response ()
10
10
{
11
11
$ this
12
12
->given (
13
13
$ this ->newTestedInstance (
14
14
new \Rezzza \SymfonyRestApiJson \ExceptionHttpCodeMap
15
15
)
16
16
)
17
- ->exception (function () {
18
- $ this ->testedInstance ->onKernelException ($ this ->dispatchException (new \Exception ('boum ' )));
19
- })
20
- ->hasMessage ('boum ' )
21
- ->isInstanceOf ('Exception ' )
17
+ ->when (
18
+ $ event = $ this ->dispatchException (new \Exception ('boum ' )),
19
+ $ this ->testedInstance ->onKernelException ($ event )
20
+ )
21
+ ->then
22
+ ->variable ($ event ->getResponse ())
23
+ ->isNull ()
22
24
;
23
25
}
24
26
You can’t perform that action at this time.
0 commit comments