File tree Expand file tree Collapse file tree 5 files changed +62
-16
lines changed Expand file tree Collapse file tree 5 files changed +62
-16
lines changed Original file line number Diff line number Diff line change 22 "strategy" : " semver" ,
33 "major" : 0 ,
44 "minor" : 8 ,
5- "patch" : 1 ,
5+ "patch" : 2 ,
66 "build" : 0
77}
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ function dispatch( Application $App ) : void
5959 }
6060 catch ( \Exception $ e )
6161 {
62- echo $ e -> getMessage (). " <br> " . $ e -> getTraceAsString ( );
62+ echo $ App -> handleException ( $ e );
6363 }
6464}
6565
Original file line number Diff line number Diff line change @@ -478,5 +478,43 @@ public function clearExpiredCache(): int
478478
479479 return 0 ;
480480 }
481+
482+ public function beautifyException ( \Exception $ e ): string
483+ {
484+ // this function should return a nicely formatted HTML representation of the exception
485+ $ ExceptionType = get_class ( $ e );
486+ $ Message = htmlspecialchars ( $ e ->getMessage (), ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8 ' );
487+ $ File = htmlspecialchars ( $ e ->getFile (), ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8 ' );
488+ $ Line = $ e ->getLine ();
489+ $ Trace = nl2br ( htmlspecialchars ( $ e ->getTraceAsString (), ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8 ' ) );
490+ $ Html = "<html><head><title>Exception: $ ExceptionType</title>
491+ <style>
492+ body { font-family: Arial, sans-serif; margin: 20px; }
493+ h1 { color: #c00; }
494+ pre { background-color: #f4f4f4; padding: 10px; border: 1px solid #ddd; }
495+ </style>
496+ </head><body> " ;
497+ $ Html .= "<h1>Exception: $ ExceptionType</h1> " ;
498+ $ Html .= "<p><strong>Message:</strong> $ Message</p> " ;
499+ $ Html .= "<p><strong>File:</strong> $ File</p> " ;
500+ $ Html .= "<p><strong>Line:</strong> $ Line</p> " ;
501+ $ Html .= "<h2>Stack Trace:</h2><pre> $ Trace</pre> " ;
502+ $ Html .= "</body></html> " ;
503+
504+ return $ Html ;
505+ }
506+
507+ public function handleException ( \Exception $ e ) : string
508+ {
509+ if ( $ this ->getCaptureOutput () )
510+ {
511+ $ this ->_Output .= $ this ->beautifyException ( $ e );
512+ return $ this ->_Output ;
513+ }
514+ else
515+ {
516+ return $ this ->beautifyException ( $ e );
517+ }
518+ }
481519}
482520
Original file line number Diff line number Diff line change @@ -236,21 +236,25 @@ public function testDispatchParametersStructure()
236236 */
237237 public function testDispatchWithException ()
238238 {
239- // Create mock application that throws exception
240- $ App = $ this ->createMock ( Application::class );
241- $ App ->expects ( $ this ->once () )
242- ->method ( 'run ' )
243- ->willThrowException ( new \Exception ( 'Test exception ' ) );
244-
245- // Capture output
246- ob_start ();
247- dispatch ( $ App );
248- $ Output = ob_get_clean ();
249-
250- // Should output 'Ouch.' when exception is caught
251- $ this ->assertStringContainsString ( 'Exception ' , $ Output );
239+ // Create mock application with handleException
240+ $ App = $ this ->createMock (Application::class);
241+ $ App ->expects ($ this ->once ())
242+ ->method ('run ' )
243+ ->willThrowException (new \Exception ('Test exception ' ));
244+ $ App ->expects ($ this ->once ())
245+ ->method ('handleException ' )
246+ ->willReturnCallback ( function ( $ e ) {
247+ return "Exception: " . $ e ->getMessage ();
248+ });
249+
250+ // Capture output
251+ ob_start ();
252+ dispatch ($ App );
253+ $ Output = ob_get_clean ();
254+
255+ $ this ->assertStringContainsString ('Exception ' , $ Output );
252256 }
253-
257+
254258 /**
255259 * Test ClearExpiredCache function
256260 */
Original file line number Diff line number Diff line change 1+ * Added exception formatting.
2+
3+ ## 0.8.2 2025-11-07
4+
15* Added routing exception output.
26
37## 0.8.1 2025-11-07
You can’t perform that action at this time.
0 commit comments