Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316533

Change subject: Forward error message parameters in RepoApiError
......................................................................

Forward error message parameters in RepoApiError

Change-Id: I044a28c863758a39b92f473a76813c0ff027b1bd
---
M src/RepoApiError.js
M tests/RepoApiError.tests.js
2 files changed, 10 insertions(+), 6 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseJavaScriptApi 
refs/changes/33/316533/1

diff --git a/src/RepoApiError.js b/src/RepoApiError.js
index bea0256..eaeaae1 100644
--- a/src/RepoApiError.js
+++ b/src/RepoApiError.js
@@ -16,18 +16,19 @@
  *
  * @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 +54,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 +70,7 @@
                        }
                }
 
-               return mw.msg( msgKey );
+               return mw.msg.apply( mw.msg, [ msgKey ].concat( parameters || 
[] ) );
        }
 
 } );
@@ -84,12 +86,14 @@
  */
 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.
+                       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 +105,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: newchange
Gerrit-Change-Id: I044a28c863758a39b92f473a76813c0ff027b1bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseJavaScriptApi
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to