summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-09-03 19:17:20 +0200
committerJo-Philipp Wich <jo@mein.io>2019-09-10 15:28:16 +0200
commitaef4bc3a23529425b8036be2baed4327efaf85bb (patch)
treec0b5a4fbf6c661b29a08ff2e28db0c0804c16c2c /modules/luci-base/htdocs
parent93af8a3af8c389f3f24ec95a2cda9b455050e4fe (diff)
luci-base: rpc.js: add getStatusText() call
The new function allows translating an ubus return code into a human readable error message. Also report the called object and method on ubus rpc errors. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/rpc.js31
1 files changed, 25 insertions, 6 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/rpc.js b/modules/luci-base/htdocs/luci-static/resources/rpc.js
index e12c2f77ee..e6a1bb24dc 100644
--- a/modules/luci-base/htdocs/luci-static/resources/rpc.js
+++ b/modules/luci-base/htdocs/luci-static/resources/rpc.js
@@ -44,8 +44,8 @@ return L.Class.extend({
msg = null;
if (!res.ok)
- L.error('RPCError', 'RPC call failed with HTTP error %d: %s',
- res.status, res.statusText || '?');
+ L.error('RPCError', 'RPC call to %s/%s failed with HTTP error %d: %s',
+ req.object, req.method, res.status, res.statusText || '?');
msg = res.json();
@@ -55,9 +55,9 @@ return L.Class.extend({
/* verify message frame */
if (typeof(msg) == 'object' && msg.jsonrpc == '2.0') {
if (typeof(msg.error) == 'object' && msg.error.code && msg.error.message)
- req.reject(new Error('RPC call failed with error %d: %s'
- .format(msg.error.code, msg.error.message || '?')));
- else if (Array.isArray(msg.result) && msg.result[0] == 0)
+ req.reject(new Error('RPC call to %s/%s failed with error %d: %s'
+ .format(req.object, req.method, msg.error.code, msg.error.message || '?')));
+ else if (Array.isArray(msg.result))
ret = (msg.result.length > 1) ? msg.result[1] : msg.result[0];
}
else {
@@ -120,7 +120,9 @@ return L.Class.extend({
resolve: resolveFn,
reject: rejectFn,
params: params,
- priv: priv
+ priv: priv,
+ object: options.object,
+ method: options.method
};
/* build message object */
@@ -156,5 +158,22 @@ return L.Class.extend({
setBaseURL: function(url) {
rpcBaseURL = url;
+ },
+
+ getStatusText: function(statusCode) {
+ switch (statusCode) {
+ case 0: return _('Command OK');
+ case 1: return _('Invalid command');
+ case 2: return _('Invalid argument');
+ case 3: return _('Method not found');
+ case 4: return _('Resource not found');
+ case 5: return _('No data received');
+ case 6: return _('Permission denied');
+ case 7: return _('Request timeout');
+ case 8: return _('Not supported');
+ case 9: return _('Unspecified error');
+ case 10: return _('Connection lost');
+ default: return _('Unknown error code');
+ }
}
});