1717use Micro \Component \EventEmitter \EventListenerInterface ;
1818use Micro \Kernel \App \Business \Event \ApplicationReadyEvent ;
1919use Micro \Kernel \App \Business \Event \ApplicationReadyEventInterface ;
20+ use Micro \Plugin \Http \Exception \HttpException ;
2021use Micro \Plugin \Http \Facade \HttpFacadeInterface ;
2122use Micro \Plugin \Http \Facade \HttpRoadrunnerFacadeInterface ;
23+ use Micro \Plugin \Logger \Facade \LoggerFacadeInterface ;
2224use Nyholm \Psr7 \Factory \Psr17Factory ;
2325use Nyholm \Psr7 \Response as Psr7Response ;
2426use Spiral \RoadRunner ;
3032 public function __construct (
3133 private HttpFacadeInterface $ httpFacade ,
3234 private HttpRoadrunnerFacadeInterface $ httpRoadrunnerFacade ,
35+ private LoggerFacadeInterface $ loggerFacade ,
3336 ) {
3437 }
3538
@@ -48,6 +51,7 @@ public function on(EventInterface $event): void
4851 return ;
4952 }
5053
54+ $ logger = $ this ->loggerFacade ->getLogger ();
5155 $ httpFoundationFactory = new HttpFoundationFactory ();
5256 $ psr17Factory = new Psr17Factory ();
5357 $ httpMessageFactory = new PsrHttpFactory ($ psr17Factory , $ psr17Factory , $ psr17Factory , $ psr17Factory );
@@ -58,8 +62,14 @@ public function on(EventInterface $event): void
5862 while (true ) {
5963 try {
6064 $ request = $ psr7 ->waitRequest ();
65+ if (!$ request ) {
66+ break ;
67+ }
6168 } catch (\Throwable $ e ) {
62- $ psr7 ->respond (new Psr7Response (400 ));
69+ $ psr7 ->respond (new Psr7Response (500 ));
70+ if (!($ e instanceof HttpException)) {
71+ $ logger ->error ('RoadRunner Exception [Request]: ' .$ e ->getMessage (), ['exception ' => $ e ]);
72+ }
6373
6474 continue ;
6575 }
@@ -71,6 +81,7 @@ public function on(EventInterface $event): void
7181 } catch (\Throwable $ e ) {
7282 $ psr7 ->respond (new Psr7Response (500 ));
7383 $ psr7 ->getWorker ()->error ((string ) $ e );
84+ $ logger ->error ('RoadRunner Exception [Response]: ' .$ e ->getMessage (), ['exception ' => $ e ]);
7485 } finally {
7586 if (++$ i === $ gcCollectStep ) {
7687 gc_collect_cycles ();
0 commit comments