luci-base: change button-text from Dismiss to Close in UCI changes overview
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / rpc.js
index 20b77c18fc813ec520ca4af2eef6cf3d88e78857..f37f7bb6a4e8f432d1ddaccaa7d86cb3f2485329 100644 (file)
@@ -33,9 +33,6 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ {
                                                req[i].params[2]
                                        );
                }
-               else if (req.params) {
-                       q += '/%s.%s'.format(req.params[1], req.params[2]);
-               }
 
                return request.post(rpcBaseURL + q, req, {
                        timeout: (L.env.rpctimeout || 20) * 1000,
@@ -93,6 +90,10 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ {
                        ret = msg.result;
                }
                else if (Array.isArray(msg.result)) {
+                       if (req.raise && msg.result[0] !== 0)
+                               L.raise('RPCError', 'RPC call to %s/%s failed with ubus code %d: %s',
+                                       req.object, req.method, msg.result[0], this.getStatusText(msg.result[0]));
+
                        ret = (msg.result.length > 1) ? msg.result[1] : msg.result[0];
                }
 
@@ -228,6 +229,10 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ {
         * Specfies an optional filter function which is invoked to transform the
         * received reply data before it is returned to the caller.
         *
+        * @property {boolean} [reject=false]
+        * If set to `true`, non-zero ubus call status codes are treated as fatal
+        * error and lead to the rejection of the call promise. The default
+        * behaviour is to resolve with the call return code value instead.
         */
 
        /**
@@ -316,7 +321,8 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ {
                                        params:  params,
                                        priv:    priv,
                                        object:  options.object,
-                                       method:  options.method
+                                       method:  options.method,
+                                       raise:   options.reject
                                };
 
                                /* build message object */