diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-04-10 22:50:41 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-04-10 22:50:41 +0200 |
commit | bd713f870a974d46b214d07d85ac4a895d85a122 (patch) | |
tree | 41da5cef1467fbdad124d54740c4b8f7b036472c /modules | |
parent | 465891ff0239b8fdafb737d01e3f05205a14319b (diff) |
luci-base: rpc.js: add ability to reject nonzero ubus statuses
Add a new declare option `reject` which makes the generated RPC call
function reject with an error in case the remote ubus call returned
a non-zero status.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/rpc.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/rpc.js b/modules/luci-base/htdocs/luci-static/resources/rpc.js index 20b77c18f..7bfc91336 100644 --- a/modules/luci-base/htdocs/luci-static/resources/rpc.js +++ b/modules/luci-base/htdocs/luci-static/resources/rpc.js @@ -93,6 +93,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 +232,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 +324,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 */ |