ArticleTargetSaver: Fix handling for data.result !== 'success'

The comment here seems to be wrong, as far as I can tell, this
case can only happen when viewing a diff with no changes
(`data.result === 'nochanges'`) or saving an edit and getting
a captcha (`data.result === 'error'`).

The handling here, added in the recent refactor
b0f4b4c94e, causes both of these
cases to behave wrong (displaying the error message, instead of
empty diff / captcha form).

Change-Id: I305e8ca9ff769c229a93d5fb3307e545a0227f2f
This commit is contained in:
Bartosz Dziewoński 2019-11-18 16:05:33 -05:00
parent 1e890f975f
commit 1dc642ee57
2 changed files with 10 additions and 7 deletions

View file

@ -1545,11 +1545,14 @@ ve.init.mw.ArticleTarget.prototype.getWikitextDiffPromise = function ( doc ) {
oldid: this.revid,
etag: this.etag
}, 'diff' ).then( function ( data ) {
if ( data.result === 'nochanges' ) {
return data.diff;
}, function ( code, response ) {
// ArticleTargetSaver treats this as an error, this is silly
if ( response.visualeditoredit && response.visualeditoredit.result === 'nochanges' ) {
target.emit( 'noChanges' );
return null;
}
return data.diff;
return ve.createDeferred().reject( code, response ).promise();
} );
this.wikitextDiffPromise
.done( this.emit.bind( this, 'showChanges' ) )

View file

@ -256,11 +256,11 @@
html: 'Invalid response from server'
};
} else if ( data.result !== 'success' ) {
// Note, this could be any of db failure, hookabort, badtoken or even a captcha
error = {
code: 'failure',
html: 'Save failure: ' + mw.html.escape( data.result )
};
// This can only happen when:
// * viewing a diff with no changes (`data.result === 'nochanges'`)
// * saving an edit and getting a captcha (`data.result === 'error'`)
// It's a silly special case...
return $.Deferred().reject( 'no-error-no-success', response ).promise();
} else {
// paction specific errors
switch ( data.paction ) {