@@ -54,9 +54,12 @@ class PlainTextFallbackResponder
5454 * @param int $status_code HTTP status code (default: 500).
5555 * @throws Throwable in DEVMODE
5656 */
57- public function respond (Throwable $ e , int $ status_code = StatusCode::HTTP_INTERNAL_SERVER_ERROR ): never
58- {
59- if (defined ('DEVMODE ' ) && DEVMODE ) {
57+ public function respond (
58+ Throwable $ e ,
59+ int $ status_code = StatusCode::HTTP_INTERNAL_SERVER_ERROR ,
60+ ?string $ status_message = null
61+ ): never {
62+ if (\defined ('DEVMODE ' ) && DEVMODE ) {
6063 throw $ e ;
6164 }
6265
@@ -65,12 +68,13 @@ public function respond(Throwable $e, int $status_code = StatusCode::HTTP_INTERN
6568 header ('Content-Type: text/plain; charset=UTF-8 ' );
6669 }
6770
68- $ incident_id = session_id () . '_ ' . (new \Random \Randomizer ())->getInt (1 , 9999 );
71+ $ session_prefix = session_id () !== '' ? session_id () : 'no-session ' ;
72+ $ incident_id = $ session_prefix . '_ ' . (new \Random \Randomizer ())->getInt (1 , 9999 );
6973 $ timestamp = (new DateTimeImmutable ())
7074 ->setTimezone (new DateTimeZone ('UTC ' ))
7175 ->format ('Y-m-d\TH:i:s\Z ' );
7276
73- echo " Internal Server Error \n" ;
77+ echo ( $ status_message ?? ' Internal Server Error ' ) . " \n" ;
7478 echo "Incident: $ incident_id \n" ;
7579 echo "Timestamp: $ timestamp \n" ;
7680
@@ -80,11 +84,12 @@ public function respond(Throwable $e, int $status_code = StatusCode::HTTP_INTERN
8084 echo "Message: {$ e ->getMessage ()}\n" ;
8185 }
8286
83- error_log (sprintf (
87+ error_log (
88+ \sprintf (
8489 "[%s] INCIDENT %s — Uncaught %s: %s in %s:%d \nStack trace: \n%s \n" ,
8590 $ timestamp ,
8691 $ incident_id ,
87- get_class ($ e ),
92+ \ get_class ($ e ),
8893 $ e ->getMessage (),
8994 $ e ->getFile (),
9095 $ e ->getLine (),
0 commit comments