18
18
use FastyBird \JsonApi \Exceptions ;
19
19
use FastyBird \JsonApi \JsonApi ;
20
20
use Fig \Http \Message \StatusCodeInterface ;
21
+ use IPub ;
21
22
use Neomerx ;
22
23
use Neomerx \JsonApi \Contracts ;
23
24
use Neomerx \JsonApi \Schema ;
27
28
use Psr \Log ;
28
29
use Throwable ;
29
30
31
+ if (!class_exists ('IPub\SlimRouter\Exceptions\HttpException ' )) {
32
+ class_alias ('IPub\SlimRouter\Exceptions\HttpException ' , Throwable::class);
33
+ }
34
+
30
35
/**
31
36
* {JSON:API} formatting output handling middleware
32
37
*
@@ -74,6 +79,7 @@ public function process(Message\ServerRequestInterface $request, Server\RequestH
74
79
return $ handler ->handle ($ request );
75
80
76
81
} catch (Throwable $ ex ) {
82
+ var_dump ($ ex ->getMessage ());
77
83
$ response = $ this ->responseFactory ->createResponse (StatusCodeInterface::STATUS_BAD_REQUEST );
78
84
79
85
if ($ ex instanceof Exceptions \IJsonApiException) {
@@ -90,6 +96,22 @@ public function process(Message\ServerRequestInterface $request, Server\RequestH
90
96
91
97
$ response ->getBody ()->write ($ content );
92
98
}
99
+ } elseif ($ ex instanceof IPub \SlimRouter \Exceptions \HttpException) {
100
+ $ response = $ response ->withStatus ($ ex ->getCode ());
101
+
102
+ $ content = $ this ->getEncoder ()
103
+ ->encodeError (new Schema \Error (
104
+ null ,
105
+ null ,
106
+ null ,
107
+ (string ) $ ex ->getCode (),
108
+ (string ) $ ex ->getCode (),
109
+ $ ex ->getTitle (),
110
+ $ ex ->getDescription ()
111
+ ));
112
+
113
+ $ response ->getBody ()
114
+ ->write ($ content );
93
115
} else {
94
116
$ this ->logger ->error ('[FB::JSON_API] An error occurred during request handling ' , [
95
117
'exception ' => [
0 commit comments