From: Brad Jorsch Date: Sat, 20 May 2017 10:09:20 +0000 (+0200) Subject: ApiSandbox: Fix HTTP error handling X-Git-Tag: 1.31.0-rc.0~3202^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22brouteur%22%2C%28%24id_rubrique%20?a=commitdiff_plain;h=c7e60349bf41020e9974d5199872da1fdbf5212e;p=lhc%2Fweb%2Fwiklou.git ApiSandbox: Fix HTTP error handling Since bf69459, ApiSandbox seems to stall out when an API request results in an HTTP error (e.g. due to a PHP fatal error). Before that revision, it displayed the 'apisandbox-results-error' message in this situation. Apparently the jQuery 3 changes to Deferred behavior caused it to be impossible to have a then() filter return `this` (or anything else) in order to avoid replacing the existing promise that's being resolved or rejected. Bug: T165857 Change-Id: I3f646cdfe7fe8987437980790788821f51e728d1 --- diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index f53850a545..da8bdcda19 100644 --- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js +++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js @@ -1100,25 +1100,18 @@ } } ) .then( null, function ( code, data, result, jqXHR ) { + var deferred = $.Deferred(); + if ( code !== 'http' ) { // Not really an error, work around mw.Api thinking it is. - return $.Deferred() - .resolve( result, jqXHR ) - .promise(); + deferred.resolve( result, jqXHR ); + } else { + // Just forward it. + deferred.reject.apply( deferred, arguments ); } - return this; + return deferred.promise(); } ) - .fail( function ( code, data ) { - var details = 'HTTP error: ' + data.exception; - $result.empty() - .append( - new OO.ui.LabelWidget( { - label: mw.message( 'apisandbox-results-error', details ).text(), - classes: [ 'error' ] - } ).$element - ); - } ) - .done( function ( data, jqXHR ) { + .then( function ( data, jqXHR ) { var m, loadTime, button, clear, ct = jqXHR.getResponseHeader( 'Content-Type' ); @@ -1195,6 +1188,15 @@ .on( 'click', button.setDisabled, [ true ], button ) .$element.appendTo( $result ); } + }, function ( code, data ) { + var details = 'HTTP error: ' + data.exception; + $result.empty() + .append( + new OO.ui.LabelWidget( { + label: mw.message( 'apisandbox-results-error', details ).text(), + classes: [ 'error' ] + } ).$element + ); } ); } ); },