From a1cedee3c4a45fcecdae9e2d06b13f92404d7f6a Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sat, 25 Aug 2012 03:57:54 +0400 Subject: [PATCH] New hook ApiMain::onException Allows custom logging of API errors Change-Id: If8841c33998dff96448a7eb8dbe95d68119e068f --- docs/hooks.txt | 5 +++++ includes/api/ApiMain.php | 3 +++ 2 files changed, 8 insertions(+) diff --git a/docs/hooks.txt b/docs/hooks.txt index ca4657823e..7844aaf48c 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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. diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 420acd3d9e..2a94a65f4f 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -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() ); -- 2.20.1