Preserve warnings on API error
authorYuri Astrakhan <yuriastrakhan@gmail.com>
Fri, 18 Jan 2013 06:45:43 +0000 (01:45 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 23 Jan 2013 19:40:45 +0000 (14:40 -0500)
* In case of an error, any warnings generated by API modules before
the error will be preserved in the result.
* Spelling

Change-Id: Ib61a1da90e9ce5df60ceccd0de8c6de9e49a22d6

RELEASE-NOTES-1.21
includes/api/ApiMain.php

index 01ff993..a34cd17 100644 (file)
@@ -187,6 +187,7 @@ production.
   a redirect and its target.
 * (bug 43849) ApiQueryImageInfo no longer throws exceptions with ForeignDBRepo
   redirects.
+* On error, any warnings generated before that error will be shown in the result.
 
 === API internal changes in 1.21 ===
 * For debugging only, a new global $wgDebugAPI removes many API restrictions when true.
index 3f82d3c..70c31c1 100644 (file)
@@ -384,7 +384,7 @@ class ApiMain extends ApiBase {
                                }
                        }
 
-                       // Handle any kind of exception by outputing properly formatted error message.
+                       // Handle any kind of exception by outputting properly formatted error message.
                        // If this fails, an unhandled exception should be thrown so that global error
                        // handler will process and log it.
 
@@ -622,7 +622,6 @@ class ApiMain extends ApiBase {
                        if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) {
                                ApiResult::setContent( $errMessage, $this->makeHelpMsg() );
                        }
-
                } else {
                        global $wgShowSQLErrors, $wgShowExceptionDetails;
                        // Something is seriously wrong
@@ -639,6 +638,10 @@ class ApiMain extends ApiBase {
                        ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' );
                }
 
+               // Remember all the warnings to re-add them later
+               $oldResult = $result->getData();
+               $warnings = isset( $oldResult['warnings'] ) ? $oldResult['warnings'] : null;
+
                $result->reset();
                $result->disableSizeCheck();
                // Re-add the id
@@ -646,11 +649,13 @@ class ApiMain extends ApiBase {
                if ( !is_null( $requestid ) ) {
                        $result->addValue( null, 'requestid', $requestid );
                }
-
                if ( $wgShowHostnames ) {
                        // servedby is especially useful when debugging errors
                        $result->addValue( null, 'servedby', wfHostName() );
                }
+               if ( $warnings !== null ) {
+                       $result->addValue( null, 'warnings', $warnings );
+               }
 
                $result->addValue( null, 'error', $errMessage );