mw.Api: Deprecate mw.Api.errors, mw.Api.warnings
[lhc/web/wiklou.git] / resources / src / mediawiki / api.js
index 529bd9f..d5032da 100644 (file)
                                                        jqXHR
                                                );
                                        } else if ( result.error ) {
+                                               // errorformat=bc
                                                code = result.error.code === undefined ? 'unknown' : result.error.code;
                                                apiDeferred.reject( code, result, result, jqXHR );
+                                       } else if ( result.errors ) {
+                                               // errorformat!=bc
+                                               code = result.errors[ 0 ].code === undefined ? 'unknown' : result.errors[ 0 ].code;
+                                               apiDeferred.reject( code, result, result, jqXHR );
                                        } else {
                                                apiDeferred.resolve( result, jqXHR );
                                        }
                                                        } );
                                                }
 
-                                               // Different error, pass on to let caller handle the error code
-                                               return this;
+                                               // Let caller handle the error code
+                                               return $.Deferred().rejectWith( this, arguments );
                                        }
                                );
                        } ).promise( { abort: function () {
                 *
                 * @since 1.22
                 * @param {string} type Token type
+                * @param {string} [assert]
                 * @return {jQuery.Promise} Received token.
                 */
                getToken: function ( type, assert ) {
                        promiseGroup = promises[ this.defaults.ajax.url ];
                        d = promiseGroup && promiseGroup[ type + 'Token' ];
 
+                       if ( !promiseGroup ) {
+                               promiseGroup = promises[ this.defaults.ajax.url ] = {};
+                       }
+
                        if ( !d ) {
                                apiPromise = this.get( {
                                        action: 'query',
                                                // Clear promise. Do not cache errors.
                                                delete promiseGroup[ type + 'Token' ];
 
-                                               // Pass on to allow the caller to handle the error
-                                               return this;
+                                               // Let caller handle the error code
+                                               return $.Deferred().rejectWith( this, arguments );
                                        } )
                                        // Attach abort handler
                                        .promise( { abort: apiPromise.abort } );
 
                                // Store deferred now so that we can use it again even if it isn't ready yet
-                               if ( !promiseGroup ) {
-                                       promiseGroup = promises[ this.defaults.ajax.url ] = {};
-                               }
                                promiseGroup[ type + 'Token' ] = d;
                        }
 
        /**
         * @static
         * @property {Array}
-        * List of errors we might receive from the API.
-        * For now, this just documents our expectation that there should be similar messages
-        * available.
+        * Very incomplete and outdated list of errors we might receive from the API. Do not use.
+        * @deprecated since 1.29
         */
        mw.Api.errors = [
                // occurs when POST aborted
                'stashwrongowner',
                'stashnosuchfilekey'
        ];
+       mw.log.deprecate( mw.Api, 'errors', mw.Api.errors );
 
        /**
         * @static
         * @property {Array}
-        * List of warnings we might receive from the API.
-        * For now, this just documents our expectation that there should be similar messages
-        * available.
+        * Very incomplete and outdated list of warnings we might receive from the API. Do not use.
+        * @deprecated since 1.29
         */
        mw.Api.warnings = [
                'duplicate',
                'exists'
        ];
+       mw.log.deprecate( mw.Api, 'warnings', mw.Api.warnings );
 
 }( mediaWiki, jQuery ) );