@@ -130,22 +130,31 @@ public function exceptionHandler(Throwable $exception)
130130 $ uri = $ this ->request ->getPath () === '' ? '/ ' : $ this ->request ->getPath ();
131131 $ routeInfo = '[Method: ' . $ this ->request ->getMethod () . ', Route: ' . $ uri . '] ' ;
132132
133- log_message ('critical ' , " {message} \n{routeInfo} \nin {exFile} on line {exLine}. \n{trace} " , [
133+ log_message ('critical ' , get_class ( $ exception ) . " : {message} \n{routeInfo} \nin {exFile} on line {exLine}. \n{trace} " , [
134134 'message ' => $ exception ->getMessage (),
135135 'routeInfo ' => $ routeInfo ,
136136 'exFile ' => clean_path ($ exception ->getFile ()), // {file} refers to THIS file
137137 'exLine ' => $ exception ->getLine (), // {line} refers to THIS line
138138 'trace ' => self ::renderBacktrace ($ exception ->getTrace ()),
139139 ]);
140- }
141140
142- $ this ->response = Services::response ();
141+ // Get the first exception.
142+ $ last = $ exception ;
143143
144- // Get the first exception.
145- while ($ prevException = $ exception ->getPrevious ()) {
146- $ exception = $ prevException ;
144+ while ($ prevException = $ last ->getPrevious ()) {
145+ $ last = $ prevException ;
146+
147+ log_message ('critical ' , '[Caused by] ' . get_class ($ prevException ) . ": {message} \nin {exFile} on line {exLine}. \n{trace} " , [
148+ 'message ' => $ prevException ->getMessage (),
149+ 'exFile ' => clean_path ($ prevException ->getFile ()), // {file} refers to THIS file
150+ 'exLine ' => $ prevException ->getLine (), // {line} refers to THIS line
151+ 'trace ' => self ::renderBacktrace ($ prevException ->getTrace ()),
152+ ]);
153+ }
147154 }
148155
156+ $ this ->response = Services::response ();
157+
149158 if (method_exists ($ this ->config , 'handler ' )) {
150159 // Use new ExceptionHandler
151160 $ handler = $ this ->config ->handler ($ statusCode , $ exception );
@@ -330,7 +339,14 @@ protected function render(Throwable $exception, int $statusCode)
330339 */
331340 protected function collectVars (Throwable $ exception , int $ statusCode ): array
332341 {
333- $ trace = $ exception ->getTrace ();
342+ // Get the first exception.
343+ $ firstException = $ exception ;
344+
345+ while ($ prevException = $ firstException ->getPrevious ()) {
346+ $ firstException = $ prevException ;
347+ }
348+
349+ $ trace = $ firstException ->getTrace ();
334350
335351 if ($ this ->config ->sensitiveDataInTrace !== []) {
336352 $ trace = $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
0 commit comments