@@ -275,8 +275,10 @@ public static function printErrorPage($error_msg, $hint = '', $statusCode = 500)
275275 * @suppress PhanAccessMethodInternal
276276 */
277277 public static function printExceptionErrorPage ($ exception , $ statusCode = 503 ) {
278+ $ debug = false ;
278279 http_response_code ($ statusCode );
279280 try {
281+ $ debug = \OC ::$ server ->getSystemConfig ()->getValue ('debug ' , false );
280282 $ request = \OC ::$ server ->getRequest ();
281283 $ content = new \OC_Template ('' , 'exception ' , 'error ' , false );
282284 $ content ->assign ('errorClass ' , get_class ($ exception ));
@@ -285,7 +287,7 @@ public static function printExceptionErrorPage($exception, $statusCode = 503) {
285287 $ content ->assign ('file ' , $ exception ->getFile ());
286288 $ content ->assign ('line ' , $ exception ->getLine ());
287289 $ content ->assign ('exception ' , $ exception );
288- $ content ->assign ('debugMode ' , \ OC :: $ server -> getSystemConfig ()-> getValue ( ' debug ' , false ) );
290+ $ content ->assign ('debugMode ' , $ debug );
289291 $ content ->assign ('remoteAddr ' , $ request ->getRemoteAddress ());
290292 $ content ->assign ('requestID ' , $ request ->getId ());
291293 $ content ->printPage ();
@@ -296,22 +298,28 @@ public static function printExceptionErrorPage($exception, $statusCode = 503) {
296298 $ logger ->logException ($ e , ['app ' => 'core ' ]);
297299 } catch (Throwable $ e ) {
298300 // no way to log it properly - but to avoid a white page of death we send some output
299- header ('Content-Type: text/plain; charset=utf-8 ' );
300- print ("Internal Server Error \n\n" );
301- print ("The server encountered an internal error and was unable to complete your request. \n" );
302- print ("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report. \n" );
303- print ("More details can be found in the server log. \n" );
301+ self ::printPlainErrorPage ($ e , $ debug );
304302
305303 // and then throw it again to log it at least to the web server error log
306304 throw $ e ;
307305 }
308306
309- header ('Content-Type: text/plain; charset=utf-8 ' );
310- print ("Internal Server Error \n\n" );
311- print ("The server encountered an internal error and was unable to complete your request. \n" );
312- print ("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report. \n" );
313- print ("More details can be found in the server log. \n" );
307+ self ::printPlainErrorPage ($ e , $ debug );
314308 }
315309 die ();
316310 }
311+
312+ private static function printPlainErrorPage (\Throwable $ exception , bool $ debug = false ) {
313+ header ('Content-Type: text/plain; charset=utf-8 ' );
314+ print ("Internal Server Error \n\n" );
315+ print ("The server encountered an internal error and was unable to complete your request. \n" );
316+ print ("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report. \n" );
317+ print ("More details can be found in the server log. \n" );
318+
319+ if ($ debug ) {
320+ print ("\n" );
321+ print ($ exception ->getMessage () . ' ' . $ exception ->getFile () . ' at ' . $ exception ->getLine () . "\n" );
322+ print ($ exception ->getTraceAsString ());
323+ }
324+ }
317325}
0 commit comments