@@ -66,14 +66,7 @@ private function renderErrorResponse(Status $status, ?HttpRequestFailed $excepti
6666 fn ($ trace ) => arr ($ trace )->removeKeys ('args ' )->toArray (),
6767 )->toArray (),
6868 ] : [
69- 'message ' => $ exception ?->getMessage() ?: match ($ status ) {
70- Status::INTERNAL_SERVER_ERROR => 'An unexpected server error occurred ' ,
71- Status::NOT_FOUND => 'This page could not be found on the server ' ,
72- Status::FORBIDDEN => 'You do not have permission to access this page ' ,
73- Status::UNAUTHORIZED => 'You must be authenticated in to access this page ' ,
74- Status::UNPROCESSABLE_CONTENT => 'The request could not be processed due to invalid data ' ,
75- default => null ,
76- },
69+ 'message ' => static ::getErrorMessage ($ status , $ exception ),
7770 ],
7871 )->setStatus ($ status );
7972 }
@@ -84,14 +77,7 @@ private function renderErrorResponse(Status $status, ?HttpRequestFailed $excepti
8477 'css ' => $ this ->getStyleSheet (),
8578 'status ' => $ status ->value ,
8679 'title ' => $ status ->description (),
87- 'message ' => $ exception ?->getMessage() ?: match ($ status ) {
88- Status::INTERNAL_SERVER_ERROR => 'An unexpected server error occurred ' ,
89- Status::NOT_FOUND => 'This page could not be found on the server ' ,
90- Status::FORBIDDEN => 'You do not have permission to access this page ' ,
91- Status::UNAUTHORIZED => 'You must be authenticated in to access this page ' ,
92- Status::UNPROCESSABLE_CONTENT => 'The request could not be processed due to invalid data ' ,
93- default => null ,
94- },
80+ 'message ' => static ::getErrorMessage ($ status , $ exception ),
9581 ]),
9682 );
9783 }
@@ -100,4 +86,18 @@ private function getStyleSheet(): string
10086 {
10187 return Filesystem \read_file (__DIR__ . '/HttpErrorResponse/style.css ' );
10288 }
89+
90+ private static function getErrorMessage (Status $ status , ?Throwable $ exception = null ): ?string
91+ {
92+ return (
93+ $ exception ?->getMessage() ?: match ($ status ) {
94+ Status::INTERNAL_SERVER_ERROR => 'An unexpected server error occurred ' ,
95+ Status::NOT_FOUND => 'This page could not be found on the server ' ,
96+ Status::FORBIDDEN => 'You do not have permission to access this page ' ,
97+ Status::UNAUTHORIZED => 'You must be authenticated in to access this page ' ,
98+ Status::UNPROCESSABLE_CONTENT => 'The request could not be processed due to invalid data ' ,
99+ default => null ,
100+ }
101+ );
102+ }
103103}
0 commit comments