jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/328372 )
Change subject: Standardize on `code, result` params for deferred rejections
......................................................................
Standardize on `code, result` params for deferred rejections
Deferreds were being rejected very inconsistently. This made it
hard to handle them properly, as you'd have to backtrack multiple
methods to figure out what kind of data you could expect to deal
with (and often, you could be dealing with multiple different
types of params, eventually)
This will standardize all API call rejections to `code, result`,
where code is the error code (string) and result is the response
object that is guaranteed to have a `code` and `info` key (both
strings)
Change-Id: I78f4afb7333317b783ab24dcdf0140783eb4f469
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M resources/handlers/mw.ApiUploadFormDataHandler.js
M resources/handlers/mw.ApiUploadPostHandler.js
M resources/handlers/mw.FirefoggHandler.js
M resources/mw.UploadWizard.js
M resources/mw.UploadWizardDetails.js
M resources/mw.UploadWizardLicenseInput.js
M resources/mw.UploadWizardUpload.js
M resources/mw.UploadWizardUploadInterface.js
M resources/transports/mw.FirefoggTransport.js
M resources/transports/mw.FormDataTransport.js
M tests/qunit/transports/mw.FormDataTransport.test.js
14 files changed, 194 insertions(+), 171 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index aa73e19..51f9333 100644
--- a/extension.json
+++ b/extension.json
@@ -306,6 +306,8 @@
"api-error-spamblacklist",
"api-error-offline",
"api-error-parsererror",
+ "api-error-firefogg",
+ "api-error-aborted",
"mwe-upwiz-api-warning-was-deleted",
"mwe-upwiz-api-warning-exists",
"mwe-upwiz-tutorial-error-localized-file-missing",
diff --git a/i18n/en.json b/i18n/en.json
index 7039f9d..9369e94 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -18,6 +18,8 @@
"api-error-spamblacklist": "The text you wanted to save was blocked by
the spam filter.\nThis is probably caused by a link to a blacklisted external
site.",
"api-error-offline": "Could not proceed due to network connectivity
issues. Make sure you have a working internet connection and try again.",
"api-error-parsererror": "The server responded with an invalid JSON
document. This could be a problem with the API, or you could be using a proxy
server that prevents you from uploading files.",
+ "api-error-firefogg": "Encoding failed.",
+ "api-error-aborted": "Upload aborted.",
"mwe-upwiz-unavailable": "Your browser is not compatible with
UploadWizard or has JavaScript turned off, so we are showing you a simple
upload form. ([https://www.mediawiki.org/wiki/UploadWizard#Compatibility View
compatibility requirements].)",
"mwe-upwiz-extension-disabled": "This page has been disabled due to
temporary technical problems. In the meantime try the standard upload form.",
"mwe-upwiz-step-tutorial": "Learn",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 3d4406f..2cababe 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -44,6 +44,8 @@
"api-error-spamblacklist": "API error message that can be used for
client side localisation of API errors. This is a shorter version of
{{msg-mw|spamprotectiontext}} that is specific to file uploads.",
"api-error-offline": "Error message for when files could not be
uploaded as a result of bad/lost internet connection.",
"api-error-parsererror": "Error message for when, for an unknown
reason, the server sent the client an invalid response.",
+ "api-error-firefogg": "Error message for when encoding of ogg files
fails.",
+ "api-error-aborted": "Error message for when an upload was aborted.",
"mwe-upwiz-unavailable": "Shown if the user visits Special:UploadWizard
using a browser that can't display the wizard due to JavaScript being disabled
or lack of support for modern features.",
"mwe-upwiz-extension-disabled": "Shown if the UploadWizard page has
been disabled.",
"mwe-upwiz-step-tutorial": "{| align=\"right\"\n|
[[file:commons-uw-L524.png|Initial \"{{MediaWiki:mwe-upwiz-step-file/en}}\"
page|thumb|right]]\n| [[file:commons-uw-L521.png|Beginning of
\"{{MediaWiki:mwe-upwiz-step-tutorial/en}}\" page|thumb|right]]\n|
[[file:commons-uw-L522.png|Center of
\"{{MediaWiki:mwe-upwiz-step-tutorial/en}}\" page|thumb|right]]\n|
[[file:commons-uw-L523.png|End of \"{{MediaWiki:mwe-upwiz-step-tutorial/en}}\"
page|thumb|right]]\n|} This is a short greyed or bolded label, in the top bar
of all pages of the [[:mw:Extension:UploadWizard|MediaWiki Upload Wizard]].",
diff --git a/resources/handlers/mw.ApiUploadFormDataHandler.js
b/resources/handlers/mw.ApiUploadFormDataHandler.js
index f0622ed..fcc5174 100644
--- a/resources/handlers/mw.ApiUploadFormDataHandler.js
+++ b/resources/handlers/mw.ApiUploadFormDataHandler.js
@@ -72,15 +72,15 @@
uw.eventFlowLogger.logApiError( 'file', result );
}
handler.upload.setTransported(
result );
- }, function ( code, info, result ) {
- if ( !result || result.error ||
( result.upload && result.upload.warnings ) ) {
+ }, function ( code, result ) {
+ if ( result.upload &&
result.upload.warnings ) {
uw.eventFlowLogger.logApiError( 'file', result );
}
- handler.upload.setTransported(
result );
+
handler.upload.setTransportError( code, result );
} );
- }, function ( code, info, result ) {
+ }, function ( code, result ) {
uw.eventFlowLogger.logApiError( 'file', result
);
- handler.upload.setError( code, info );
+ handler.upload.setTransportError( code, result
);
} );
}
};
diff --git a/resources/handlers/mw.ApiUploadPostHandler.js
b/resources/handlers/mw.ApiUploadPostHandler.js
index 49b0084..cce7082 100644
--- a/resources/handlers/mw.ApiUploadPostHandler.js
+++ b/resources/handlers/mw.ApiUploadPostHandler.js
@@ -25,12 +25,12 @@
url: this.upload.file.url,
filename: this.beginTime.toString() +
this.upload.getFilename()
} )
- .fail( function ( code, info, result ) {
+ .fail( function ( code, result ) {
uw.eventFlowLogger.logApiError( 'file',
result );
- handler.upload.setError( code, info );
+ handler.upload.setTransportError( code,
result );
} )
.done( function ( result ) {
- if ( !result || result.error || (
result.upload && result.upload.warnings ) ) {
+ if ( result.upload &&
result.upload.warnings ) {
uw.eventFlowLogger.logApiError(
'file', result );
}
handler.upload.setTransported( result );
diff --git a/resources/handlers/mw.FirefoggHandler.js
b/resources/handlers/mw.FirefoggHandler.js
index 7244ad2..0887191 100644
--- a/resources/handlers/mw.FirefoggHandler.js
+++ b/resources/handlers/mw.FirefoggHandler.js
@@ -63,7 +63,12 @@
if ( !this.upload.title || !( /^[\x00-\x7F]*$/.test(
this.upload.title.getMain() ) ) ) {
this.upload.setError( 'firefogg-nonascii', '' );
this.upload.ui.setStatus(
'mwe-upwiz-firefogg-nonascii' );
- return $.Deferred().reject();
+ return $.Deferred().reject( 'firefogg', {
+ error: {
+ code: 'firefogg',
+ info: 'Encoding failed:
non-ASCII filename'
+ }
+ } );
}
mw.log( 'mw.FirefoggHandler::start> Upload start!' );
@@ -96,9 +101,9 @@
upload.file = file;
transport.uploadHandler = new
mw.ApiUploadFormDataHandler( upload, handler.api );
return transport.uploadHandler.start();
- }, function ( code, info, result ) {
+ }, function ( code, result ) {
mw.log(
'FirefoggTransport::getTransport> Transport done ' + JSON.stringify( result ) );
- upload.setTransported( result );
+ upload.setTransportError( code, result
);
} );
}
};
diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index 5a0e230..0c5e036 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -96,20 +96,25 @@
return mw.Api.prototype.ajax.apply( this, [
parameters, ajaxOptions ] ).then(
null, // done handler - doesn't need
overriding
function ( code, result ) { // fail
handler
- if ( code === 'http' && result
) {
- if ( result.xhr &&
result.xhr.status === 0 ) {
- code =
'offline';
- }
+ var response = { error: {
+ code: code,
+ info: result.textStatus
|| 'unknown'
+ } };
- result = {
- error: {
- code:
code,
- info:
result.textStatus
- }
- };
+ if ( result.error &&
result.error.info ) {
+ // in case of
success-but-has-errors, we have a valid result
+ response = result;
+ } else if ( result.textStatus
&& result.textStatus === 'timeout' ) {
+ code = 'timeout';
+ response.error.code =
'timeout';
+ response.error.info =
'timeout';
+ } else if ( code === 'http' &&
result.xhr && result.xhr.status === 0 ) {
+ code = 'offline';
+ response.error.code =
'offline';
+ response.error.info =
'offline';
}
- return $.Deferred().reject(
code, result, result );
+ return $.Deferred().reject(
code, response, response );
}
);
};
diff --git a/resources/mw.UploadWizardDetails.js
b/resources/mw.UploadWizardDetails.js
index 9c63451..0f02092 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -731,7 +731,7 @@
* @return {jQuery.Promise}
*/
submit: function () {
- var params, wikiText;
+ var params;
$( 'form', this.containerDiv ).submit();
@@ -754,14 +754,8 @@
params.async = true;
}
- wikiText = this.getWikiText();
-
- if ( wikiText !== false ) {
- params.text = wikiText;
- return this.submitInternal( params );
- }
-
- return $.Deferred().reject();
+ params.text = this.getWikiText();
+ return this.submitInternal( params );
},
/**
@@ -774,7 +768,7 @@
submitInternal: function ( params ) {
var
details = this,
- apiPromise =
details.upload.api.postWithEditToken( params );
+ apiPromise = this.upload.api.postWithEditToken(
params );
return apiPromise
.then(
function ( result ) {
@@ -783,11 +777,11 @@
}
return
details.handleSubmitResult( result, params );
},
- function ( code, info, result ) {
+ function ( code, result ) {
uw.eventFlowLogger.logApiError(
'details', result );
details.upload.state = 'error';
- details.processError( code,
info );
- return $.Deferred().reject(
code, info );
+ details.processError( code,
result );
+ return $.Deferred().reject(
code, result );
}
)
.promise( { abort: apiPromise.abort } );
@@ -810,10 +804,16 @@
if ( result && result.upload && result.upload.result
=== 'Poll' ) {
// if async publishing takes longer than 10
minutes give up
if ( ( ( new Date() ).getTime() -
this.firstPoll ) > 10 * 60 * 1000 ) {
- return $.Deferred().reject(
'server-error', 'unknown server error' );
+ return deferred.reject( 'server-error',
{ error: {
+ code: 'server-error',
+ info: 'unknown server error'
+ } } );
} else {
if ( result.upload.stage === undefined
&& window.console ) {
- return $.Deferred().reject(
'no-stage', 'Unable to check file\'s status' );
+ return deferred.reject(
'no-stage', { error: {
+ code: 'no-stage',
+ info: 'Unable to check
file\'s status'
+ } } );
} else {
// Messages that can be
returned:
// * mwe-upwiz-queued
@@ -873,16 +873,16 @@
return this.submitInternal( params );
} else if ( result && result.upload &&
result.upload.warnings ) {
if ( warnings.thumb || warnings[ 'thumb-name' ]
) {
- this.recoverFromError( mw.message(
'mwe-upwiz-error-title-thumbnail' ), 'error-title-thumbnail' );
+ this.recoverFromError(
'error-title-thumbnail', mw.message( 'mwe-upwiz-error-title-thumbnail' ) );
} else if ( warnings.badfilename ) {
- this.recoverFromError( mw.message(
'mwe-upwiz-error-title-invalid' ), 'title-invalid' );
+ this.recoverFromError( 'title-invalid',
mw.message( 'mwe-upwiz-error-title-invalid' ) );
} else if ( warnings[ 'bad-prefix' ] ) {
- this.recoverFromError( mw.message(
'mwe-upwiz-error-title-senselessimagename' ), 'title-senselessimagename' );
+ this.recoverFromError(
'title-senselessimagename', mw.message(
'mwe-upwiz-error-title-senselessimagename' ) );
} else if ( existingFile ) {
existingFileUrl = mw.config.get(
'wgServer' ) + mw.Title.makeTitle( NS_FILE, existingFile ).getUrl();
- this.recoverFromError( mw.message(
'mwe-upwiz-api-warning-exists', existingFileUrl ), 'api-warning-exists' );
+ this.recoverFromError(
'api-warning-exists', mw.message( 'mwe-upwiz-api-warning-exists',
existingFileUrl ) );
} else if ( warnings.duplicate ) {
- this.recoverFromError( mw.message(
'mwe-upwiz-upload-error-duplicate' ), 'upload-error-duplicate' );
+ this.recoverFromError(
'upload-error-duplicate', mw.message( 'mwe-upwiz-upload-error-duplicate' ) );
} else if ( warnings[ 'duplicate-archive' ] !==
undefined ) {
// warnings[ 'duplicate-archive' ] may
be '' (empty string) for revdeleted files
if ( this.upload.ignoreWarning[
'duplicate-archive' ] ) {
@@ -892,7 +892,7 @@
return this.submitInternal(
params );
} else {
// This should _never_ happen,
but just in case....
- this.recoverFromError(
mw.message( 'mwe-upwiz-upload-error-duplicate-archive' ),
'upload-error-duplicate-archive' );
+ this.recoverFromError(
'upload-error-duplicate-archive', mw.message(
'mwe-upwiz-upload-error-duplicate-archive' ) );
}
} else {
warningsKeys = [];
@@ -900,7 +900,7 @@
warningsKeys.push( key );
} );
this.upload.state = 'error';
- this.recoverFromError( mw.message(
'api-error-unknown-warning', warningsKeys.join( ', ' ) ),
'api-error-unknown-warning' );
+ this.recoverFromError(
'api-error-unknown-warning', mw.message( 'api-error-unknown-warning',
warningsKeys.join( ', ' ) ));
}
return $.Deferred().resolve();
@@ -912,14 +912,14 @@
/**
* Create a recoverable error -- show the form again, and
highlight the problematic field.
*
- * @param {mw.Message} errorMessage Error message to show.
- * @param {string} errorCode
+ * @param {string} code
+ * @param {mw.Message} message Error message to show.
*/
- recoverFromError: function ( errorMessage, errorCode ) {
- uw.eventFlowLogger.logError( 'details', { code:
errorCode, message: errorMessage } );
+ recoverFromError: function ( code, message ) {
+ uw.eventFlowLogger.logError( 'details', { code: code,
message: message } );
this.upload.state = 'recoverable-error';
this.dataDiv.morphCrossfade( '.detailsForm' );
- this.titleDetailsField.setErrors( [ errorMessage ] );
+ this.titleDetailsField.setErrors( [ message ] );
},
/**
@@ -964,14 +964,14 @@
// 'amenableparser' will expand templates and
parser functions server-side.
// We still do the rest of wikitext parsing
here (throught jqueryMsg).
promise = this.api.loadMessagesIfMissing( [
result.error.message.key ], { amenableparser: true } );
- this.recoverFromError( mw.message( 'api-error-'
+ code, function () {
+ this.recoverFromError( code, mw.message(
'api-error-' + code, function () {
promise.done( function () {
mw.errorDialog( $( '<div>'
).msg(
result.error.message.key,
result.error.message.params
) );
} );
- } ), code );
+ } ) );
return;
}
@@ -984,17 +984,14 @@
// This could potentially also come up when an
upload is removed by the user, but in that
// case the UI is invisible anyway, so whatever.
code = 'ratelimited';
- } else if ( code === 'http' && result && result.xhr &&
result.xhr.status === 0 ) {
- // Failed to even connect to server
- code = 'offline';
}
if ( result && code ) {
if ( titleErrorMap[ code ] ) {
- this.recoverFromError( mw.message(
'mwe-upwiz-error-title-' + titleErrorMap[ code ] ), 'title-' + titleErrorMap[
code ] );
+ this.recoverFromError( 'title-' +
titleErrorMap[ code ], mw.message( 'mwe-upwiz-error-title-' + titleErrorMap[
code ] ) );
return;
} else if ( code === 'titleblacklist-forbidden'
) {
- this.recoverFromError( mw.message(
'mwe-upwiz-error-title-' + titleBlacklistMessageMap[ result.error.message.key ]
), 'title-' + titleBlacklistMessageMap[ result.error.message.key ] );
+ this.recoverFromError( 'title-' +
titleBlacklistMessageMap[ result.error.message.key ], mw.message(
'mwe-upwiz-error-title-' + titleBlacklistMessageMap[ result.error.message.key ]
) );
return;
} else {
statusKey = 'api-error-' + code;
diff --git a/resources/mw.UploadWizardLicenseInput.js
b/resources/mw.UploadWizardLicenseInput.js
index b832e76..664aa50 100644
--- a/resources/mw.UploadWizardLicenseInput.js
+++ b/resources/mw.UploadWizardLicenseInput.js
@@ -631,7 +631,7 @@
}
function error( code, result ) {
- var message = result.textStatus || result.error
&& result.error.info || undefined;
+ var message = result.error.info;
uw.eventFlowLogger.logError( 'license', { code:
code, message: message } );
show( $( '<div></div>' ).append(
diff --git a/resources/mw.UploadWizardUpload.js
b/resources/mw.UploadWizardUpload.js
index dadcfc5..40a7aaa 100644
--- a/resources/mw.UploadWizardUpload.js
+++ b/resources/mw.UploadWizardUpload.js
@@ -142,73 +142,16 @@
};
/**
- * To be executed when an individual upload finishes. Processes the
result and updates step 2's details
+ * To be executed when an individual upload finishes. Processes the
result
+ * and updates step 2's details
*
* @param {Object} result The API result in parsed JSON form
*/
mw.UploadWizardUpload.prototype.setTransported = function ( result ) {
// default error state
- var comma, warnCode, promise,
- code = 'unknown',
- info = 'unknown',
- $extra;
+ var warnCode, info;
if ( this.state === 'aborted' ) {
- return;
- }
-
- if ( result.error ) {
- // If there was an error, we can't really do anything
else, so let's get out while we can.
- if ( result.error.code ) {
- code = result.error.code;
- }
- if ( code === 'badtoken' ) {
- this.api.badToken( 'csrf' );
- // Try again once
- if ( !this.ignoreWarning[ code ] ) {
- this.removeErrors( code );
- return;
- }
- }
- if ( code === 'filetype-banned' &&
result.error.blacklisted ) {
- code = 'filetype-banned-type';
- comma = mw.message( 'comma-separator' ).text();
- info = [
- result.error.blacklisted.join( comma ),
- result.error.allowed.join( comma ),
- result.error.allowed.length,
- result.error.blacklisted.length
- ];
- } else if ( code === 'abusefilter-disallowed' || code
=== 'abusefilter-warning' || code === 'spamblacklist' ) {
- // 'amenableparser' will expand templates and
parser functions server-side.
- // We still do the rest of wikitext parsing
here (throught jqueryMsg).
- promise = this.api.loadMessagesIfMissing( [
result.error.message.key ], { amenableparser: true } );
- info = [
- function () {
- promise.done( function () {
- mw.errorDialog( $(
'<div>' ).msg(
-
result.error.message.key,
-
result.error.message.params
- ) );
- } );
- }
- ];
-
- if ( code === 'abusefilter-warning' ) {
- $extra = new OO.ui.ButtonWidget( {
- label: mw.message(
'mwe-upwiz-override' ).text(),
- title: mw.message(
'mwe-upwiz-override-upload' ).text(),
- flags: 'progressive',
- framed: false
- } ).on( 'click', function () {
- // No need to ignore the error,
AbuseFilter will only return it once
- this.start();
- }.bind( this ) ).$element;
- }
- } else if ( result.error.info ) {
- info = result.error.info;
- }
- this.setError( code, info, $extra );
return;
}
@@ -227,51 +170,110 @@
break;
case 'duplicate':
case 'duplicate-archive':
- code = warnCode;
this.setDuplicateError(
warnCode, result.upload.warnings[ warnCode ] );
- break;
+ return;
case 'nochange':
// This is like 'duplicate',
but also the filename is the same, which doesn't matter
if (
result.upload.warnings.exists ) {
- code = warnCode;
this.setDuplicateError(
'duplicate', result.upload.warnings.exists );
}
- break;
+ return;
default:
// we have an unknown warning,
so let's say what we know
- code = 'unknown-warning';
if ( typeof
result.upload.warnings[ warnCode ] === 'string' ) {
// tack the original
error code onto the warning info
info = warnCode +
mw.message( 'colon-separator' ).text() + result.upload.warnings[ warnCode ];
} else {
info =
result.upload.warnings[ warnCode ];
}
- this.setError( code, info );
- break;
+ this.setError(
'unknown-warning', info );
+ return;
}
}
}
- if ( this.state !== 'error' ) {
- if ( result.upload && result.upload.result ===
'Success' ) {
- if ( result.upload.imageinfo ) {
- this.setSuccess( result );
- } else {
- this.setError( 'noimageinfo', info );
- }
- } else if ( result.upload && result.upload.result ===
'Warning' ) {
- throw new Error( 'Your browser got back a
Warning result from the server. Please file a bug.' );
+ if ( result.upload && result.upload.result === 'Success' ) {
+ if ( result.upload.imageinfo ) {
+ this.setSuccess( result );
} else {
- this.setError( code, info );
+ this.setError( 'noimageinfo', 'unknown' );
+ }
+ } else if ( result.upload && result.upload.result === 'Warning'
) {
+ throw new Error( 'Your browser got back a Warning
result from the server. Please file a bug.' );
+ } else {
+ this.setError( 'unknown', 'unknown' );
+ }
+ };
+
+ /**
+ * To be executed when an individual upload fails
+ *
+ * @param {string} code The API error code
+ * @param {Object} result The API result in parsed JSON form
+ */
+ mw.UploadWizardUpload.prototype.setTransportError = function ( code,
result ) {
+ var comma, promise,
+ info = result.error.info,
+ $extra;
+
+ if ( this.state === 'aborted' ) {
+ return;
+ }
+
+ if ( code === 'badtoken' ) {
+ this.api.badToken( 'csrf' );
+ // Try again once
+ if ( !this.ignoreWarning[ code ] ) {
+ this.removeErrors( code );
+ return;
}
}
+
+ if ( code === 'filetype-banned' && result.error.blacklisted ) {
+ code = 'filetype-banned-type';
+ comma = mw.message( 'comma-separator' ).text();
+ info = [
+ result.error.blacklisted.join( comma ),
+ result.error.allowed.join( comma ),
+ result.error.allowed.length,
+ result.error.blacklisted.length
+ ];
+ } else if ( code === 'abusefilter-disallowed' || code ===
'abusefilter-warning' || code === 'spamblacklist' ) {
+ // 'amenableparser' will expand templates and parser
functions server-side.
+ // We still do the rest of wikitext parsing here
(throught jqueryMsg).
+ promise = this.api.loadMessagesIfMissing( [
result.error.message.key ], { amenableparser: true } );
+ info = [
+ function () {
+ promise.done( function () {
+ mw.errorDialog( $( '<div>'
).msg(
+
result.error.message.key,
+
result.error.message.params
+ ) );
+ } );
+ }
+ ];
+
+ if ( code === 'abusefilter-warning' ) {
+ $extra = new OO.ui.ButtonWidget( {
+ label: mw.message( 'mwe-upwiz-override'
).text(),
+ title: mw.message(
'mwe-upwiz-override-upload' ).text(),
+ flags: 'progressive',
+ framed: false
+ } ).on( 'click', function () {
+ // No need to ignore the error,
AbuseFilter will only return it once
+ this.start();
+ }.bind( this ) ).$element;
+ }
+ }
+
+ this.setError( code, info, $extra );
};
/**
* Helper function to generate duplicate errors in a possibly
collapsible list.
* Works with existing duplicates and deleted dupes.
*
- * @param {string} code Error code, should have matching strings in
.i18n.php
+ * @param {string} code Warning code, should have matching strings in
.i18n.php
* @param {Object} resultDuplicate Portion of the API error result
listing duplicates
*/
mw.UploadWizardUpload.prototype.setDuplicateError = function ( code,
resultDuplicate ) {
@@ -326,7 +328,7 @@
/**
* Called from any upload success condition
*
- * @param {Mixed} result -- result of AJAX call
+ * @param {Object} result -- result of AJAX call
*/
mw.UploadWizardUpload.prototype.setSuccess = function ( result ) {
this.state = 'transported';
@@ -334,18 +336,14 @@
this.ui.setStatus( 'mwe-upwiz-getting-metadata' );
- if ( result.upload ) {
- this.extractUploadInfo( result.upload );
- this.state = 'stashed';
- this.ui.showStashed();
+ this.extractUploadInfo( result.upload );
+ this.state = 'stashed';
+ this.ui.showStashed();
- this.emit( 'success' );
- // check all uploads, if they're complete, show the
next button
- // TODO Make wizard connect to 'success' event
- this.controller.showNext();
- } else {
- this.setError( 'noimageinfo' );
- }
+ this.emit( 'success' );
+ // check all uploads, if they're complete, show the next button
+ // TODO Make wizard connect to 'success' event
+ this.controller.showNext();
};
/**
diff --git a/resources/mw.UploadWizardUploadInterface.js
b/resources/mw.UploadWizardUploadInterface.js
index 89b0611..6e7973c 100644
--- a/resources/mw.UploadWizardUploadInterface.js
+++ b/resources/mw.UploadWizardUploadInterface.js
@@ -183,12 +183,8 @@
];
this.showIndicator( 'error' );
+
// is this an error that we expect to have a message for?
-
- if ( code === 'http' && info.textStatus === 'timeout' ) {
- code = 'timeout';
- }
-
if ( $.inArray( code, mw.Api.errors ) !== -1 || $.inArray(
code, moreErrorCodes ) !== -1 ) {
msgKey = 'api-error-' + code;
args = $.makeArray( info );
diff --git a/resources/transports/mw.FirefoggTransport.js
b/resources/transports/mw.FirefoggTransport.js
index 240c1ab..3215974 100644
--- a/resources/transports/mw.FirefoggTransport.js
+++ b/resources/transports/mw.FirefoggTransport.js
@@ -40,7 +40,7 @@
deferred.resolve( file );
} else {
// encoding failed
- deferred.reject( {
+ deferred.reject( 'firefogg', {
error: {
code:
'firefogg',
info: 'Encoding
failed'
diff --git a/resources/transports/mw.FormDataTransport.js
b/resources/transports/mw.FormDataTransport.js
index fb286d9..ce78bb0 100644
--- a/resources/transports/mw.FormDataTransport.js
+++ b/resources/transports/mw.FormDataTransport.js
@@ -198,7 +198,12 @@
if ( this.aborted ) {
this.api.abort();
- return $.Deferred().reject();
+ return $.Deferred().reject( 'aborted', {
+ error: {
+ code: 'aborted',
+ info: 'Aborted'
+ }
+ } );
}
// Slice API was changed and has vendor prefix for now
@@ -259,15 +264,17 @@
// shafted anyway. But some server-side errors
really are temporary...
return transport.maybeRetry(
'on unknown response',
+ response.error ? response.error.code :
'unknown-error',
response,
'uploadChunk',
file, offset
);
}
- }, function ( response ) {
+ }, function ( code, result ) {
return transport.maybeRetry(
'on error event',
- response,
+ code,
+ result,
'uploadChunk',
file, offset
);
@@ -278,20 +285,21 @@
* Handle possible retry event - rejected if maximum retries already
fired.
*
* @param {string} contextMsg
+ * @param {string} code
* @param {Object} response
* @param {string} retryMethod
* @param {File} [file]
* @param {number} [offset]
* @return {jQuery.Promise}
*/
- mw.FormDataTransport.prototype.maybeRetry = function ( contextMsg,
response, retryMethod, file, offset ) {
+ mw.FormDataTransport.prototype.maybeRetry = function ( contextMsg,
code, response, retryMethod, file, offset ) {
this.retries++;
if ( this.tooManyRetries() ) {
mw.log.warn( 'Max retries exceeded ' + contextMsg );
- return $.Deferred().reject( response );
+ return $.Deferred().reject( code, response );
} else if ( this.aborted ) {
- return $.Deferred().reject( response );
+ return $.Deferred().reject( code, response );
} else {
mw.log( 'Retry #' + this.retries + ' ' + contextMsg );
return this.retryWithMethod( retryMethod, file, offset
);
@@ -342,7 +350,12 @@
params = OO.cloneObject( this.formData );
if ( this.aborted ) {
- return $.Deferred().reject();
+ return $.Deferred().reject( 'aborted', {
+ error: {
+ code: 'aborted',
+ info: 'Aborted'
+ }
+ } );
}
if ( !this.firstPoll ) {
@@ -358,14 +371,17 @@
if ( response.upload && response.upload.result
=== 'Poll' ) {
// If concatenation takes longer than
10 minutes give up
if ( ( ( new Date() ).getTime() -
transport.firstPoll ) > 10 * 60 * 1000 ) {
- return $.Deferred().reject( {
+ return $.Deferred().reject(
'server-error', { error: {
code: 'server-error',
- info: 'unknown server
error'
- } );
+ info: 'Unknown server
error'
+ } } );
} else {
if ( response.upload.stage ===
undefined && window.console ) {
window.console.log(
'Unable to check file\'s status' );
- return
$.Deferred().reject();
+ return
$.Deferred().reject( 'server-error', { error: {
+ code:
'server-error',
+ info: 'Unknown
server error'
+ } } );
} else {
// Statuses that can be
returned:
// * queued
@@ -378,8 +394,8 @@
}
return response;
- }, function ( code, info, response ) {
- return $.Deferred().reject( response );
+ }, function ( code, result ) {
+ return $.Deferred().reject( code, result );
} );
};
diff --git a/tests/qunit/transports/mw.FormDataTransport.test.js
b/tests/qunit/transports/mw.FormDataTransport.test.js
index 617ccd8..d9828b5 100644
--- a/tests/qunit/transports/mw.FormDataTransport.test.js
+++ b/tests/qunit/transports/mw.FormDataTransport.test.js
@@ -144,10 +144,10 @@
transport.checkStatus().fail( tstub );
transport.firstPoll = 0;
postd.resolve( { upload: { result: 'Poll' } } );
- assert.ok( tstub.calledWith( {
+ assert.ok( tstub.calledWith( 'server-error', { error: {
code: 'server-error',
- info: 'unknown server error'
- } ) );
+ info: 'Unknown server error'
+ } } ) );
postd = $.Deferred();
postd2 = $.Deferred();
@@ -180,8 +180,8 @@
tstub.reset();
usstub.reset();
transport.checkStatus().fail( tstub );
- postd.reject( 500, 'testing', { error: 'testing' } );
- assert.ok( tstub.calledWith( { error: 'testing' } ) );
+ postd.reject( 'testing', { error: 'testing' } );
+ assert.ok( tstub.calledWith( 'testing', { error: 'testing' } )
);
assert.ok( !usstub.called );
} );
--
To view, visit https://gerrit.wikimedia.org/r/328372
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I78f4afb7333317b783ab24dcdf0140783eb4f469
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits