Log exceptions encountered in api.php. Check for null $wgRequest.
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 21 Sep 2008 09:38:55 +0000 (09:38 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 21 Sep 2008 09:38:55 +0000 (09:38 +0000)
includes/Exception.php
includes/api/ApiMain.php

index e2f76f2..05ddfd1 100644 (file)
@@ -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 */
index b3d8a94..ceca85c 100644 (file)
@@ -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