Merge "API: Allow for format modules that cannot handle errors"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 31 Mar 2014 17:48:47 +0000 (17:48 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 31 Mar 2014 17:48:47 +0000 (17:48 +0000)
1  2 
includes/api/ApiMain.php

diff --combined includes/api/ApiMain.php
@@@ -386,9 -386,6 +386,9 @@@ class ApiMain extends ApiBase 
         * @param Exception $e
         */
        protected function handleException( Exception $e ) {
 +              // Bug 63145: Rollback any open database transactions
 +              MWExceptionHandler::rollbackMasterChangesAndLog( $e );
 +
                // Allow extra cleanup and logging
                wfRunHooks( 'ApiMain::onException', array( $this, $e ) );
  
                global $wgShowHostnames;
  
                $result = $this->getResult();
                // Printer may not be initialized if the extractRequestParams() fails for the main module
                if ( !isset( $this->mPrinter ) ) {
                        // The printer has not been created yet. Try to manually get formatter value.
                        }
  
                        $this->mPrinter = $this->createPrinterByName( $value );
-                       if ( $this->mPrinter->getNeedsRawData() ) {
-                               $result->setRawMode();
-                       }
                }
  
+               // Printer may not be able to handle errors. This is particularly
+               // likely if the module returns something for getCustomPrinter().
+               if ( !$this->mPrinter->canPrintErrors() ) {
+                       $this->mPrinter->safeProfileOut();
+                       $this->mPrinter = $this->createPrinterByName( self::API_DEFAULT_FORMAT );
+               }
+               // Update raw mode flag for the selected printer.
+               $result->setRawMode( $this->mPrinter->getNeedsRawData() );
                if ( $e instanceof UsageException ) {
                        // User entered incorrect parameters - print usage screen
                        $errMessage = $e->getMessageArray();