1818use FastyBird \JsonApi \Exceptions ;
1919use FastyBird \JsonApi \JsonApi ;
2020use Fig \Http \Message \StatusCodeInterface ;
21+ use IPub ;
2122use Neomerx ;
2223use Neomerx \JsonApi \Contracts ;
2324use Neomerx \JsonApi \Schema ;
2728use Psr \Log ;
2829use Throwable ;
2930
31+ if (!class_exists ('IPub\SlimRouter\Exceptions\HttpException ' )) {
32+ class_alias ('IPub\SlimRouter\Exceptions\HttpException ' , Throwable::class);
33+ }
34+
3035/**
3136 * {JSON:API} formatting output handling middleware
3237 *
@@ -74,6 +79,7 @@ public function process(Message\ServerRequestInterface $request, Server\RequestH
7479 return $ handler ->handle ($ request );
7580
7681 } catch (Throwable $ ex ) {
82+ var_dump ($ ex ->getMessage ());
7783 $ response = $ this ->responseFactory ->createResponse (StatusCodeInterface::STATUS_BAD_REQUEST );
7884
7985 if ($ ex instanceof Exceptions \IJsonApiException) {
@@ -90,6 +96,22 @@ public function process(Message\ServerRequestInterface $request, Server\RequestH
9096
9197 $ response ->getBody ()->write ($ content );
9298 }
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 );
93115 } else {
94116 $ this ->logger ->error ('[FB::JSON_API] An error occurred during request handling ' , [
95117 'exception ' => [
0 commit comments