X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=modules%2Fluci-base%2Fhtdocs%2Fluci-static%2Fresources%2Frpc.js;h=f37f7bb6a4e8f432d1ddaccaa7d86cb3f2485329;hb=ddf6357cdae574b5e88213fa6af0a96f695e4283;hp=9b642444fafac9299efe6298efecfd46e35f1680;hpb=cbd6b5e5517fb3286e31a367fd9aaeb29410882e;p=project%2Fluci.git diff --git a/modules/luci-base/htdocs/luci-static/resources/rpc.js b/modules/luci-base/htdocs/luci-static/resources/rpc.js index 9b642444fa..f37f7bb6a4 100644 --- a/modules/luci-base/htdocs/luci-static/resources/rpc.js +++ b/modules/luci-base/htdocs/luci-static/resources/rpc.js @@ -1,4 +1,6 @@ 'use strict'; +'require baseclass'; +'require request'; var rpcRequestID = 1, rpcSessionID = L.env.sessionid || '00000000000000000000000000000000', @@ -14,7 +16,7 @@ var rpcRequestID = 1, * The `LuCI.rpc` class provides high level ubus JSON-RPC abstractions * and means for listing and invoking remove RPC methods. */ -return L.Class.extend(/** @lends LuCI.rpc.prototype */ { +return baseclass.extend(/** @lends LuCI.rpc.prototype */ { /* privates */ call: function(req, cb, nobatch) { var q = ''; @@ -31,11 +33,8 @@ return L.Class.extend(/** @lends LuCI.rpc.prototype */ { req[i].params[2] ); } - else if (req.params) { - q += '/%s.%s'.format(req.params[1], req.params[2]); - } - return L.Request.post(rpcBaseURL + q, req, { + return request.post(rpcBaseURL + q, req, { timeout: (L.env.rpctimeout || 20) * 1000, nobatch: nobatch, credentials: true @@ -91,6 +90,10 @@ return L.Class.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]; } @@ -226,6 +229,10 @@ return L.Class.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. */ /** @@ -314,7 +321,8 @@ return L.Class.extend(/** @lends LuCI.rpc.prototype */ { params: params, priv: priv, object: options.object, - method: options.method + method: options.method, + raise: options.reject }; /* build message object */