New hook ApiMain::onException
authorMax Semenik <semenik@gmail.com>
Fri, 24 Aug 2012 23:57:54 +0000 (03:57 +0400)
committerMax Semenik <semenik@gmail.com>
Wed, 29 Aug 2012 16:42:48 +0000 (20:42 +0400)
Allows custom logging of API errors

Change-Id: If8841c33998dff96448a7eb8dbe95d68119e068f

docs/hooks.txt
includes/api/ApiMain.php

index ca46578..7844aaf 100644 (file)
@@ -397,6 +397,11 @@ is the User object. In the hook, just add your callback to the
 $tokenFunctions array and return true (returning false makes no sense)
 $tokenFunctions: array(action => callback)
 
+'ApiMain::onException': Called by ApiMain::executeActionWithErrorHandling()
+when an exception is thrown during API action execution.
+$apiMain: Calling ApiMain instance.
+$e: Exception object.
+
 'ApiRsdServiceApis': Add or remove APIs from the RSD services list.
 Each service should have its own entry in the $apis array and have a
 unique name, passed as key for the array that represents the service data.
index 420acd3..2a94a65 100644 (file)
@@ -368,6 +368,9 @@ class ApiMain extends ApiBase {
                try {
                        $this->executeAction();
                } catch ( Exception $e ) {
+                       // Allow extra cleanup and logging
+                       wfRunHooks( 'ApiMain::onException', array( $this, $e ) );
+
                        // Log it
                        if ( !( $e instanceof UsageException ) ) {
                                wfDebugLog( 'exception', $e->getLogMessage() );