From: Tim Starling Date: Sun, 21 Sep 2008 09:38:55 +0000 (+0000) Subject: Log exceptions encountered in api.php. Check for null $wgRequest. X-Git-Tag: 1.31.0-rc.0~45179 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=9f84a2fe832e96c98385aa10c5594569d94471ad;p=lhc%2Fweb%2Fwiklou.git Log exceptions encountered in api.php. Check for null $wgRequest. --- diff --git a/includes/Exception.php b/includes/Exception.php index e2f76f2a10..05ddfd107a 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -129,7 +129,16 @@ class MWException extends Exception { $file = $this->getFile(); $line = $this->getLine(); $message = $this->getMessage(); - return $wgRequest->getRequestURL() . " Exception from line $line of $file: $message"; + if ( isset( $wgRequest ) ) { + $url = $wgRequest->getRequestURL(); + if ( !$url ) { + $url = '[no URL]'; + } + } else { + $url = '[no req]'; + } + + return "$url Exception from line $line of $file: $message"; } /** Output the exception report using HTML */ diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index b3d8a94f72..ceca85c642 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -257,6 +257,11 @@ class ApiMain extends ApiBase { try { $this->executeAction(); } catch (Exception $e) { + // Log it + if ( $e instanceof MWException ) { + wfDebugLog( 'exception', $e->getLogMessage() ); + } + // // Handle any kind of exception by outputing properly formatted error message. // If this fails, an unhandled exception should be thrown so that global error