From: Brad Jorsch Date: Tue, 29 Mar 2016 14:09:14 +0000 (-0400) Subject: ApiSandbox: Work around mw.Api treating an empty response as failure X-Git-Tag: 1.31.0-rc.0~7478^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=a299ac05475f1e70844aa5d432d4b07cf6702156;p=lhc%2Fweb%2Fwiklou.git ApiSandbox: Work around mw.Api treating an empty response as failure We use a 'then' function to turn the pseudo-failure back into a success. This also adjusts mw.Api to pass the actual result and jqXHR to the failure function for non-HTTP errors. Sadly the existing parameters passed on failure are something of a big mess, so this isn't as nice as it might otherwise be to preserve compatibility. Bug: T131129 Change-Id: Ic5da24edeac6285fbce0785f0789dddcd2dc15a9 --- diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index a2d106dec7..3cfc52c51b 100644 --- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js +++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js @@ -906,6 +906,15 @@ return xhr; } } ) + .then( null, function ( code, data, result, jqXHR ) { + if ( code !== 'http' ) { + // Not really an error, work around mw.Api thinking it is. + return $.Deferred() + .resolve( result, jqXHR ) + .promise(); + } + return this; + } ) .fail( function ( code, data ) { var details = 'HTTP error: ' + data.exception; $result.empty() diff --git a/resources/src/mediawiki/api.js b/resources/src/mediawiki/api.js index 10e0c56387..64e5976c5c 100644 --- a/resources/src/mediawiki/api.js +++ b/resources/src/mediawiki/api.js @@ -239,11 +239,13 @@ .done( function ( result, textStatus, jqXHR ) { if ( result === undefined || result === null || result === '' ) { apiDeferred.reject( 'ok-but-empty', - 'OK response but empty result (check HTTP headers?)' + 'OK response but empty result (check HTTP headers?)', + result, + jqXHR ); } else if ( result.error ) { var code = result.error.code === undefined ? 'unknown' : result.error.code; - apiDeferred.reject( code, result ); + apiDeferred.reject( code, result, result, jqXHR ); } else { apiDeferred.resolve( result, jqXHR ); }