luci-base: network.js: simplify rpc error handling
Use L.resolveDefault() catch unexpected RPC replies and rename declared rpc functions in a consistent manner. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
45e57cf1db
commit
d5ffab23b6
1 changed files with 21 additions and 89 deletions
|
@ -44,13 +44,13 @@ var iface_patterns_wireless = [
|
||||||
|
|
||||||
var iface_patterns_virtual = [ ];
|
var iface_patterns_virtual = [ ];
|
||||||
|
|
||||||
var callLuciNetdevs = rpc.declare({
|
var callLuciNetworkDevices = rpc.declare({
|
||||||
object: 'luci',
|
object: 'luci',
|
||||||
method: 'getNetworkDevices',
|
method: 'getNetworkDevices',
|
||||||
expect: { '': {} }
|
expect: { '': {} }
|
||||||
});
|
});
|
||||||
|
|
||||||
var callLuciWifidevs = rpc.declare({
|
var callLuciWirelessDevices = rpc.declare({
|
||||||
object: 'luci',
|
object: 'luci',
|
||||||
method: 'getWirelessDevices',
|
method: 'getWirelessDevices',
|
||||||
expect: { '': {} }
|
expect: { '': {} }
|
||||||
|
@ -62,11 +62,17 @@ var callLuciIfaddrs = rpc.declare({
|
||||||
expect: { result: [] }
|
expect: { result: [] }
|
||||||
});
|
});
|
||||||
|
|
||||||
var callLuciBoardjson = rpc.declare({
|
var callLuciBoardJSON = rpc.declare({
|
||||||
object: 'luci',
|
object: 'luci',
|
||||||
method: 'getBoardJSON'
|
method: 'getBoardJSON'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var callLuciHostHints = rpc.declare({
|
||||||
|
object: 'luci',
|
||||||
|
method: 'getHostHints',
|
||||||
|
expect: { '': {} }
|
||||||
|
});
|
||||||
|
|
||||||
var callIwinfoAssoclist = rpc.declare({
|
var callIwinfoAssoclist = rpc.declare({
|
||||||
object: 'iwinfo',
|
object: 'iwinfo',
|
||||||
method: 'assoclist',
|
method: 'assoclist',
|
||||||
|
@ -82,7 +88,7 @@ var callIwinfoScan = rpc.declare({
|
||||||
expect: { results: [] }
|
expect: { results: [] }
|
||||||
});
|
});
|
||||||
|
|
||||||
var callNetworkInterfaceStatus = rpc.declare({
|
var callNetworkInterfaceDump = rpc.declare({
|
||||||
object: 'network.interface',
|
object: 'network.interface',
|
||||||
method: 'dump',
|
method: 'dump',
|
||||||
expect: { 'interface': [] }
|
expect: { 'interface': [] }
|
||||||
|
@ -94,88 +100,19 @@ var callNetworkDeviceStatus = rpc.declare({
|
||||||
expect: { '': {} }
|
expect: { '': {} }
|
||||||
});
|
});
|
||||||
|
|
||||||
var callGetProtoHandlers = rpc.declare({
|
var callNetworkProtoHandlers = rpc.declare({
|
||||||
object: 'network',
|
object: 'network',
|
||||||
method: 'get_proto_handlers',
|
method: 'get_proto_handlers',
|
||||||
expect: { '': {} }
|
expect: { '': {} }
|
||||||
});
|
});
|
||||||
|
|
||||||
var callGetHostHints = rpc.declare({
|
|
||||||
object: 'luci',
|
|
||||||
method: 'getHostHints',
|
|
||||||
expect: { '': {} }
|
|
||||||
});
|
|
||||||
|
|
||||||
var _init = null,
|
var _init = null,
|
||||||
_state = null,
|
_state = null,
|
||||||
_protocols = {},
|
_protocols = {},
|
||||||
_protospecs = {};
|
_protospecs = {};
|
||||||
|
|
||||||
function getInterfaceState(cache) {
|
|
||||||
return callNetworkInterfaceStatus().then(function(state) {
|
|
||||||
if (!Array.isArray(state))
|
|
||||||
throw !1;
|
|
||||||
return state;
|
|
||||||
}).catch(function() {
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDeviceState(cache) {
|
|
||||||
return callNetworkDeviceStatus().then(function(state) {
|
|
||||||
if (!L.isObject(state))
|
|
||||||
throw !1;
|
|
||||||
return state;
|
|
||||||
}).catch(function() {
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getIfaddrState(cache) {
|
|
||||||
return callLuciIfaddrs().then(function(addrs) {
|
|
||||||
if (!Array.isArray(addrs))
|
|
||||||
throw !1;
|
|
||||||
return addrs;
|
|
||||||
}).catch(function() {
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNetdevState(cache) {
|
|
||||||
return callLuciNetdevs().then(function(state) {
|
|
||||||
if (!L.isObject(state))
|
|
||||||
throw !1;
|
|
||||||
return state;
|
|
||||||
}).catch(function() {
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getWifidevState(cache) {
|
|
||||||
return callLuciWifidevs().then(function(state) {
|
|
||||||
if (!L.isObject(state))
|
|
||||||
throw !1;
|
|
||||||
return state;
|
|
||||||
}).catch(function() {
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBoardState(cache) {
|
|
||||||
return callLuciBoardjson().then(function(state) {
|
|
||||||
if (!L.isObject(state))
|
|
||||||
throw !1;
|
|
||||||
return state;
|
|
||||||
}).catch(function() {
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getProtocolHandlers(cache) {
|
function getProtocolHandlers(cache) {
|
||||||
return callGetProtoHandlers().then(function(protos) {
|
return callNetworkProtoHandlers().then(function(protos) {
|
||||||
if (!L.isObject(protos))
|
|
||||||
throw !1;
|
|
||||||
|
|
||||||
/* Register "none" protocol */
|
/* Register "none" protocol */
|
||||||
if (!protos.hasOwnProperty('none'))
|
if (!protos.hasOwnProperty('none'))
|
||||||
Object.assign(protos, { none: { no_device: false } });
|
Object.assign(protos, { none: { no_device: false } });
|
||||||
|
@ -199,16 +136,6 @@ function getProtocolHandlers(cache) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHostHints(cache) {
|
|
||||||
return callGetHostHints().then(function(hosts) {
|
|
||||||
if (!L.isObject(hosts))
|
|
||||||
throw !1;
|
|
||||||
return hosts;
|
|
||||||
}).catch(function() {
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getWifiStateBySid(sid) {
|
function getWifiStateBySid(sid) {
|
||||||
var s = uci.get('wireless', sid);
|
var s = uci.get('wireless', sid);
|
||||||
|
|
||||||
|
@ -433,10 +360,15 @@ function maskToPrefix(mask, v6) {
|
||||||
function initNetworkState(refresh) {
|
function initNetworkState(refresh) {
|
||||||
if (_state == null || refresh) {
|
if (_state == null || refresh) {
|
||||||
_init = _init || Promise.all([
|
_init = _init || Promise.all([
|
||||||
getInterfaceState(), getDeviceState(), getBoardState(),
|
L.resolveDefault(callNetworkInterfaceDump(), []),
|
||||||
getIfaddrState(), getNetdevState(), getWifidevState(),
|
L.resolveDefault(callNetworkDeviceStatus(), {}),
|
||||||
getHostHints(), getProtocolHandlers(),
|
L.resolveDefault(callLuciBoardJSON(), {}),
|
||||||
uci.load('network'), uci.load('wireless'), uci.load('luci')
|
L.resolveDefault(callLuciIfaddrs(), []),
|
||||||
|
L.resolveDefault(callLuciNetworkDevices(), {}),
|
||||||
|
L.resolveDefault(callLuciWirelessDevices(), {}),
|
||||||
|
L.resolveDefault(callLuciHostHints(), {}),
|
||||||
|
getProtocolHandlers(),
|
||||||
|
uci.load(['network', 'wireless', 'luci'])
|
||||||
]).then(function(data) {
|
]).then(function(data) {
|
||||||
var netifd_ifaces = data[0],
|
var netifd_ifaces = data[0],
|
||||||
netifd_devs = data[1],
|
netifd_devs = data[1],
|
||||||
|
|
Loading…
Reference in a new issue