jenkins-bot has submitted this change and it was merged.
Change subject: Forward error message parameters in RepoApiError
..
Forward error message parameters in RepoApiError
Required for I99d8d79.
Change-Id: I044a28c863758a39b92f473a76813c0ff027b1bd
---
M src/RepoApiError.js
M tests/RepoApiError.tests.js
2 files changed, 18 insertions(+), 7 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/RepoApiError.js b/src/RepoApiError.js
index bea0256..6c5d447 100644
--- a/src/RepoApiError.js
+++ b/src/RepoApiError.js
@@ -16,18 +16,24 @@
*
* @param {string} code Error code (used to determine the actual error
message).
* @param {string} detailedMessage HTML
+ * @param {string[]} [parameters]
* @param {string} [action] Generic API action (e.g. "save" or "cancel") used
to determine a
*specific message.
*/
var SELF = MODULE.RepoApiError
- = util.inherit( 'WbRepoApiError', PARENT, function( code,
detailedMessage, action ) {
+ = util.inherit( 'WbRepoApiError', PARENT, function(
+ code,
+ detailedMessage,
+ parameters,
+ action
+ ) {
this.code = code;
this.detailedMessage = detailedMessage;
this.action = action;
// native Error attributes
this.name = 'Wikibase Repo API Error';
- this.message = this.getMessage();
+ this.message = this.getMessage( parameters );
},
{
/**
@@ -53,9 +59,10 @@
/**
* Returns a short message string.
*
+* @param {string[]} [parameters]
* @return {string}
*/
- getMessage: function() {
+ getMessage: function( parameters ) {
var msgKey = this.API_ERROR_MESSAGE[this.code];
if ( !msgKey || typeof msgKey !== 'string' ) {
@@ -68,7 +75,7 @@
}
}
- return mw.msg( msgKey );
+ return mw.msg.apply( mw.msg, [ msgKey ].concat( parameters ||
[] ) );
}
} );
@@ -84,12 +91,16 @@
*/
SELF.newFromApiResponse = function( details, apiAction ) {
var errorCode = '',
+ parameters = [],
detailedMessage = '';
if ( details.error ) {
errorCode = details.error.code;
if ( details.error.messages ) {
- // HTML message from Wikibase API.
+ // HTML message in a format only Wikibase supports, see
ApiErrorReporter. The data
+ // structure supports multiple messages, but this is
not relevant in the cases
+ // API_ERROR_MESSAGE supports. Assume the first message
parameters are compatible.
+ parameters = details.error.messages[0] &&
details.error.messages[0].parameters;
detailedMessage = messagesObjectToHtml(
details.error.messages );
} else if ( details.error.info ) {
// Wikibase API no-HTML error message fall-back.
@@ -101,7 +112,7 @@
detailedMessage = mw.html.escape( String( details.exception ) );
}
- return new SELF( errorCode, detailedMessage, apiAction );
+ return new SELF( errorCode, detailedMessage, parameters, apiAction );
};
/**
diff --git a/tests/RepoApiError.tests.js b/tests/RepoApiError.tests.js
index d0f9840..5a2445a 100644
--- a/tests/RepoApiError.tests.js
+++ b/tests/RepoApiError.tests.js
@@ -30,7 +30,7 @@
'Unknown error code: Used default generic error
message.'
);
- error = new wb.api.RepoApiError( 'timeout', 'detailed message',
'remove' );
+ error = new wb.api.RepoApiError( 'timeout', 'detailed message',
[], 'remove' );
assert.equal(
error.message,
--
To view, visit https://gerrit.wikimedia.org/r/316533
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I044a28c863758a39b92f473a76813c0ff027b1bd
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/WikibaseJavaScriptApi
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE)
Gerrit-Reviewer: Hoo man
Gerrit-Reviewer: Jonas Kress (WMDE)
Gerrit-Reviewer: Thiemo Mättig (WMDE)
Gerrit-Reviewer: WMDE-jand
Gerrit-Reviewer: jenkins-bot <>
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits