Bartosz Dziewoński has uploaded a new change for review. https://gerrit.wikimedia.org/r/224451
Change subject: mediawiki.api.upload: Correct response handling of #uploadWithFormData ...................................................................... mediawiki.api.upload: Correct response handling of #uploadWithFormData * Reject instead of resolving when API reports errors, like #uploadWithIframe * Purge bad tokens correctly, like #uploadWithIframe Change-Id: I42fe6f6e921fe29dd96ce5b75ad61014a7346fc9 --- M resources/src/mediawiki.api/mediawiki.api.upload.js 1 file changed, 12 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/51/224451/1 diff --git a/resources/src/mediawiki.api/mediawiki.api.upload.js b/resources/src/mediawiki.api/mediawiki.api.upload.js index 00e0550..3db7cc4 100644 --- a/resources/src/mediawiki.api/mediawiki.api.upload.js +++ b/resources/src/mediawiki.api/mediawiki.api.upload.js @@ -277,7 +277,18 @@ }, false ); xhr.addEventListener( 'load', function ( e ) { - deferred.resolve( parseXHRResponse( e ) ); + var result = parseXHRResponse( e ); + + if ( result.error || result.warnings ) { + if ( result.error && result.error.code === 'badtoken' ) { + api.badToken( 'edit' ); + } + + deferred.reject( result.error || result.warnings ); + } else { + deferred.notify( 1 ); + deferred.resolve( result ); + } }, false ); xhr.addEventListener( 'error', function ( e ) { @@ -289,9 +300,6 @@ tokenPromise = this.getEditToken().then( function ( token ) { formData.append( 'token', token ); xhr.send( formData ); - }, function () { - // Mark the edit token as bad, it's been used. - api.badToken( 'edit' ); } ); return deferred.promise(); -- To view, visit https://gerrit.wikimedia.org/r/224451 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I42fe6f6e921fe29dd96ce5b75ad61014a7346fc9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits