17
17
use Micro \Component \EventEmitter \EventListenerInterface ;
18
18
use Micro \Kernel \App \Business \Event \ApplicationReadyEvent ;
19
19
use Micro \Kernel \App \Business \Event \ApplicationReadyEventInterface ;
20
+ use Micro \Plugin \Http \Exception \HttpException ;
20
21
use Micro \Plugin \Http \Facade \HttpFacadeInterface ;
21
22
use Micro \Plugin \Http \Facade \HttpRoadrunnerFacadeInterface ;
23
+ use Micro \Plugin \Logger \Facade \LoggerFacadeInterface ;
22
24
use Nyholm \Psr7 \Factory \Psr17Factory ;
23
25
use Nyholm \Psr7 \Response as Psr7Response ;
24
26
use Spiral \RoadRunner ;
30
32
public function __construct (
31
33
private HttpFacadeInterface $ httpFacade ,
32
34
private HttpRoadrunnerFacadeInterface $ httpRoadrunnerFacade ,
35
+ private LoggerFacadeInterface $ loggerFacade ,
33
36
) {
34
37
}
35
38
@@ -48,6 +51,7 @@ public function on(EventInterface $event): void
48
51
return ;
49
52
}
50
53
54
+ $ logger = $ this ->loggerFacade ->getLogger ();
51
55
$ httpFoundationFactory = new HttpFoundationFactory ();
52
56
$ psr17Factory = new Psr17Factory ();
53
57
$ httpMessageFactory = new PsrHttpFactory ($ psr17Factory , $ psr17Factory , $ psr17Factory , $ psr17Factory );
@@ -58,8 +62,14 @@ public function on(EventInterface $event): void
58
62
while (true ) {
59
63
try {
60
64
$ request = $ psr7 ->waitRequest ();
65
+ if (!$ request ) {
66
+ break ;
67
+ }
61
68
} 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
+ }
63
73
64
74
continue ;
65
75
}
@@ -71,6 +81,7 @@ public function on(EventInterface $event): void
71
81
} catch (\Throwable $ e ) {
72
82
$ psr7 ->respond (new Psr7Response (500 ));
73
83
$ psr7 ->getWorker ()->error ((string ) $ e );
84
+ $ logger ->error ('RoadRunner Exception [Response]: ' .$ e ->getMessage (), ['exception ' => $ e ]);
74
85
} finally {
75
86
if (++$ i === $ gcCollectStep ) {
76
87
gc_collect_cycles ();
0 commit comments