From 9f84a2fe832e96c98385aa10c5594569d94471ad Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 21 Sep 2008 09:38:55 +0000 Subject: [PATCH] Log exceptions encountered in api.php. Check for null $wgRequest. --- includes/Exception.php | 11 ++++++++++- includes/api/ApiMain.php | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 -- 2.20.1