Omada widget : Improved error handling
Omada widget: handling power as common.power in translation
This commit is contained in:
parent
1f48491406
commit
37154e327a
3 changed files with 31 additions and 19 deletions
|
@ -8,7 +8,8 @@
|
||||||
"bitrate": "{{value, rate(bits: true)}}",
|
"bitrate": "{{value, rate(bits: true)}}",
|
||||||
"percent": "{{value, percent}}",
|
"percent": "{{value, percent}}",
|
||||||
"number": "{{value, number}}",
|
"number": "{{value, number}}",
|
||||||
"ms": "{{value, number}}"
|
"ms": "{{value, number}}",
|
||||||
|
"power": "{{value, power}} W"
|
||||||
},
|
},
|
||||||
"widget": {
|
"widget": {
|
||||||
"missing_type": "Missing Widget Type: {{type}}",
|
"missing_type": "Missing Widget Type: {{type}}",
|
||||||
|
|
|
@ -40,7 +40,7 @@ export default function Component({ service }) {
|
||||||
<Block label="omada.alerts" value={t( "common.number", { value: omadaData.alerts })} />
|
<Block label="omada.alerts" value={t( "common.number", { value: omadaData.alerts })} />
|
||||||
<Block label="omada.isolatedAp" value={t("common.number", { value: omadaData.isolatedAp})} />
|
<Block label="omada.isolatedAp" value={t("common.number", { value: omadaData.isolatedAp})} />
|
||||||
<Block label="omada.connectedGateway" value={t("common.number", { value: omadaData.connectedGateways})}/>
|
<Block label="omada.connectedGateway" value={t("common.number", { value: omadaData.connectedGateways})}/>
|
||||||
<Block label="omada.powerConsumption" value={t("common.number", { value: omadaData.powerConsumption})}/>
|
<Block label="omada.powerConsumption" value={t("common.power", { value: omadaData.powerConsumption})}/>
|
||||||
<Block label="omada.availablePorts" value={t("common.number", { value: omadaData.availablePorts})}/>
|
<Block label="omada.availablePorts" value={t("common.number", { value: omadaData.availablePorts})}/>
|
||||||
<Block label="omada.connectedSwitches" value={t("common.number", { value: omadaData.connectedSwitches})} />
|
<Block label="omada.connectedSwitches" value={t("common.number", { value: omadaData.connectedSwitches})} />
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,9 @@ async function login(loginUrl, username, password, cversion) {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = JSON.parse(authResponse[2]);
|
const data = JSON.parse(authResponse[2]);
|
||||||
const status = data.errorCode;
|
const status = authResponse[0];
|
||||||
let token;
|
let token;
|
||||||
if (data.errorCode === 0) {
|
if (data.errorCode === 0) {
|
||||||
token = data.result.token;
|
token = data.result.token;
|
||||||
|
@ -70,16 +71,24 @@ export default async function omadaProxyHandler(req, res) {
|
||||||
let loginUrl;
|
let loginUrl;
|
||||||
let siteName;
|
let siteName;
|
||||||
let requestresponse;
|
let requestresponse;
|
||||||
|
|
||||||
const {url} = widget;
|
const {url} = widget;
|
||||||
|
|
||||||
const controllerInfoUrl = `${widget.url}/api/info`;
|
const controllerInfoUrl = `${widget.url}/api/info`;
|
||||||
|
|
||||||
const cInfoResponse = await httpProxy(controllerInfoUrl, {
|
const cInfoResponse = await httpProxy(controllerInfoUrl, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if (cInfoResponse[0] === 500) {
|
||||||
|
logger.debug("Getting controller version ends with Error 500");
|
||||||
|
return res.status(cInfoResponse[0]).json({error: {message: "HTTP Error", controllerInfoUrl, data: cInfoResponse[2]}});
|
||||||
|
|
||||||
|
}
|
||||||
const cidresult = cInfoResponse[2];
|
const cidresult = cInfoResponse[2];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -95,16 +104,13 @@ export default async function omadaProxyHandler(req, res) {
|
||||||
} else {
|
} else {
|
||||||
loginUrl = `${widget.url}/${cid}/api/v2/login`;
|
loginUrl = `${widget.url}/${cid}/api/v2/login`;
|
||||||
}
|
}
|
||||||
|
|
||||||
requestresponse = await login(loginUrl, widget.username, widget.password, cversion);
|
requestresponse = await login(loginUrl, widget.username, widget.password, cversion);
|
||||||
|
|
||||||
if (requestresponse[0] !== 0) {
|
if (requestresponse[1].errorCode) {
|
||||||
const message = requestresponse[1].msg;
|
return res.status(requestresponse[0]).json({error: {message: "Error logging in", url, data: requestresponse[1]}});
|
||||||
|
|
||||||
logger.debug(`HTTTP ${requestresponse[0]} logging into Omada api: ${requestresponse[1].msg}`);
|
|
||||||
return res.status(500).send(message);
|
|
||||||
}
|
}
|
||||||
const token= requestresponse[1];
|
|
||||||
|
const token = requestresponse[1];
|
||||||
// Switching to the site we want to gather stats from
|
// Switching to the site we want to gather stats from
|
||||||
// First, we get the list of sites
|
// First, we get the list of sites
|
||||||
let sitesUrl;
|
let sitesUrl;
|
||||||
|
@ -145,8 +151,8 @@ export default async function omadaProxyHandler(req, res) {
|
||||||
});
|
});
|
||||||
const listresult = JSON.parse(requestresponse[2]);
|
const listresult = JSON.parse(requestresponse[2]);
|
||||||
if (listresult.errorCode !== 0) {
|
if (listresult.errorCode !== 0) {
|
||||||
logger.debug(`HTTTP ${listresult.errorCode} getting list of sites with message ${listresult.msg}`);
|
logger.debug(`HTTTP ${requestresponse[0]} getting sites list: ${requestresponse[2].msg}`);
|
||||||
return res.status(500).send(requestresponse[2]);
|
return res.status(requestresponse[0]).json({error: {message: "Error getting sites list", url, data: requestresponse[2]}});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switching site is really needed only for Omada 3.x.x controllers
|
// Switching site is really needed only for Omada 3.x.x controllers
|
||||||
|
@ -175,8 +181,8 @@ export default async function omadaProxyHandler(req, res) {
|
||||||
});
|
});
|
||||||
const switchresult = JSON.parse(requestresponse[2]);
|
const switchresult = JSON.parse(requestresponse[2]);
|
||||||
if (switchresult.errorCode !== 0) {
|
if (switchresult.errorCode !== 0) {
|
||||||
logger.debug(`HTTTP ${switchresult.errorCode} switching site with message ${switchresult.msg}`);
|
logger.debug(`HTTTP ${requestresponse[0]} getting sites list: ${requestresponse[2]}`);
|
||||||
return res.status(500).send(switchresult);
|
return res.status(requestresponse[0]).json({error: {message: "Error switching site", url, data: requestresponse[2]}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +205,7 @@ export default async function omadaProxyHandler(req, res) {
|
||||||
const data = JSON.parse(statResponse[2]);
|
const data = JSON.parse(statResponse[2]);
|
||||||
|
|
||||||
if (data.errorCode !== 0) {
|
if (data.errorCode !== 0) {
|
||||||
return res.status(500).send(statResponse[2]);
|
return res.status(statResponse[0]).json({error: {message: "Error getting stats", url, data: statResponse[2]}});
|
||||||
}
|
}
|
||||||
connectedAp = data.result.connectedAp;
|
connectedAp = data.result.connectedAp;
|
||||||
activeuser = data.result.activeUser;
|
activeuser = data.result.activeUser;
|
||||||
|
@ -210,6 +216,11 @@ export default async function omadaProxyHandler(req, res) {
|
||||||
let siteStatsUrl;
|
let siteStatsUrl;
|
||||||
let response;
|
let response;
|
||||||
sitetoswitch = listresult.result.data.filter(site => site.name === widget.site);
|
sitetoswitch = listresult.result.data.filter(site => site.name === widget.site);
|
||||||
|
|
||||||
|
if (sitetoswitch.length === 0) {
|
||||||
|
return res.status(requestresponse[0]).json({error: {message: `Site ${widget.site} is not found`, url, data: requestresponse[2]}});
|
||||||
|
}
|
||||||
|
|
||||||
// On 5.0.0, the field we need is id, on 4.x.x, it's key ...
|
// On 5.0.0, the field we need is id, on 4.x.x, it's key ...
|
||||||
siteName = sitetoswitch[0].id ?? sitetoswitch[0].key;
|
siteName = sitetoswitch[0].id ?? sitetoswitch[0].key;
|
||||||
if (cversion < "5.0.0") {
|
if (cversion < "5.0.0") {
|
||||||
|
|
Loading…
Add table
Reference in a new issue