Send RB errors through the normal error handling process

Change-Id: I230ff6d3c9a6a183fb483f5adfd7ccdc025a07af
This commit is contained in:
Alex Monk 2016-10-06 02:18:14 +01:00 committed by James D. Forrester
parent 39aa3021a7
commit b5815e9ffd
6 changed files with 23 additions and 27 deletions

View file

@ -338,7 +338,6 @@
],
"messages": [
"visualeditor-loaderror-message",
"visualeditor-loaderror-message-noconnect",
"visualeditor-loaderror-title"
],
"targets": [

View file

@ -246,7 +246,6 @@
"visualeditor-linknodeinspector-add-label": "Add label",
"visualeditor-linknodeinspector-title": "Simple link",
"visualeditor-loaderror-message": "Error loading data from server: $1.",
"visualeditor-loaderror-message-noconnect": "Could not connect to the server",
"visualeditor-loaderror-title": "The editor could not load",
"visualeditor-loadwarning": "Error loading data from server: $1. Would you like to retry?",
"visualeditor-loadwarning-noconnect": "Could not connect to the server",

View file

@ -259,7 +259,6 @@
"visualeditor-linknodeinspector-add-label": "Label of button that converts an auto-numbered, external, labelless link into a labeled external link",
"visualeditor-linknodeinspector-title": "Title of inspector for editing auto-numbered, external, labelless links.\n\nSee also:\n* {{msg-mw|Visualeditor-annotationbutton-linknode-tooltip}}",
"visualeditor-loaderror-message": "Text shown in a message box when the editor fails to load properly due to a RESTBase call failing.\n\nParameters:\n* $1 - an error message",
"visualeditor-loaderror-message-noconnect": "Error message used in {{msg-mw|visualeditor-loaderror-message}} when the editor fails to load properly due to a RESTBase call failing due to not being able to connect.",
"visualeditor-loaderror-title": "Text shown as the title of a message box when the editor fails to load properly for some reason.",
"visualeditor-loadwarning": "Text (JavaScript confirm()) shown when the editor fails to load properly.\n\nParameters:\n* $1 - the error message from the server, in English. e.g. \"docserver-http-error\"",
"visualeditor-loadwarning-noconnect": "Error shown in {{msg-mw|visualeditor-loadwarning}} when the editor fails to load due to a connection issue.",

View file

@ -660,7 +660,7 @@ ve.init.mw.DesktopArticleTarget.prototype.cancel = function ( trackMechanism ) {
/**
* @inheritdoc
*/
ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( errorText, error ) {
ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( error, errorText ) {
var errorInfo, confirmPromptMessage;
// Parent method
ve.init.mw.DesktopArticleTarget.super.prototype.loadFail.apply( this, arguments );
@ -676,11 +676,11 @@ ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( errorText, error
}
if ( !error || error.statusText !== 'abort' ) {
if ( errorText === 'http' ) {
if ( error && error.xhr.status ) {
if ( errorText === 'http' || errorText === 'error' ) {
if ( error && ( error.status || ( error.xhr && error.xhr.status ) ) ) {
confirmPromptMessage = ve.msg(
'visualeditor-loadwarning',
'HTTP ' + error.xhr.status
'HTTP ' + ( error.status || error.xhr.status )
);
} else {
confirmPromptMessage = ve.msg(
@ -696,14 +696,21 @@ ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( errorText, error
}
}
if ( confirmPromptMessage && confirm( confirmPromptMessage ) ) {
this.load();
} else if ( !$( '#wpTextbox1' ).length ) {
// TODO: Some sort of progress bar?
this.switchToWikitextEditor( true, false );
if ( confirmPromptMessage ) {
if ( confirm( confirmPromptMessage ) ) {
this.load();
} else if ( !$( '#wpTextbox1' ).length ) {
// TODO: Some sort of progress bar?
this.switchToWikitextEditor( true, false );
} else {
// If we're switching from the wikitext editor, just deactivate
// don't try to switch back to it fully, that'd discard changes.
this.deactivate( true );
}
} else {
// If we're switching from the wikitext editor, just deactivate
// don't try to switch back to it fully, that'd discard changes.
if ( error.statusText !== 'abort' ) {
mw.log.warn( 'Failed to find error message', errorText, error );
}
this.deactivate( true );
}
};

View file

@ -247,7 +247,7 @@ ve.init.mw.ArticleTarget.prototype.loadSuccess = function ( response ) {
data = response ? response.visualeditor : null;
if ( typeof data.content !== 'string' ) {
this.loadFail( 've-api', 'No HTML content in response from server' );
this.loadFail( 'No HTML content in response from server', 've-api' );
} else {
ve.track( 'trace.parseResponse.enter' );
this.originalHtml = data.content;
@ -274,9 +274,9 @@ ve.init.mw.ArticleTarget.prototype.loadSuccess = function ( response ) {
if ( this.retriedRevIdConflict ) {
// Retried already, just error the second time.
this.loadFail(
've-api',
'Revision IDs (doc=' + docRevId + ',api=' + this.revid + ') ' +
'returned by server do not match'
'returned by server do not match',
've-api'
);
} else {
this.retriedRevIdConflict = true;
@ -358,8 +358,8 @@ ve.init.mw.ArticleTarget.prototype.surfaceReady = function () {
* This method is called within the context of a target instance.
*
* @method
* @param {string} errorTypeText Error type text from mw.Api
* @param {Object} error Object containing xhr, textStatus and exception keys
* @param {string} errorTypeText Error type text from mw.Api
* @fires loadError
*/
ve.init.mw.ArticleTarget.prototype.loadFail = function () {

View file

@ -211,16 +211,8 @@
// Page does not exist, so let the user start with a blank document.
return $.Deferred().resolve( [ '', undefined ] ).promise();
} else {
if ( response.status ) {
window.alert( mw.msg( 'visualeditor-loaderror-message', 'HTTP ' + response.status ) );
} else {
window.alert( mw.msg(
'visualeditor-loaderror-message',
mw.msg( 'visualeditor-loaderror-message-noconnect' )
) );
}
mw.log.warn( 'RESTBase load failed: ' + response.statusText );
return response;
}
}
);