From ba4cbad60103624bbf9ed6bd1fbc821570322404 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 25 Dec 2022 20:58:20 -0800 Subject: [PATCH] xteve cleanup --- src/widgets/xteve/proxy.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/widgets/xteve/proxy.js b/src/widgets/xteve/proxy.js index 22795b76..ac1b49dc 100644 --- a/src/widgets/xteve/proxy.js +++ b/src/widgets/xteve/proxy.js @@ -24,6 +24,7 @@ export default async function xteveProxyHandler(req, res) { const payload = { cmd: "status" }; if (widget.username && widget.password) { + // eslint-disable-next-line no-unused-vars const [status, contentType, data] = await httpProxy(url, { method, body: JSON.stringify({ @@ -34,14 +35,14 @@ export default async function xteveProxyHandler(req, res) { }); if (status !== 200) { - return [status, contentType, data]; + logger.debug("Error logging into xteve", status, url); + return res.status(status).json({error: {message: `HTTP Error ${status} logging into xteve`, url, data}}); } const json = JSON.parse(data.toString()); if (json?.status !== true) { - const message = "Authentication failed."; - return res.status(401).end(JSON.stringify({error: { message } })); + return res.status(401).json({error: {message: "Authentication failed", url, data}}); } payload.token = json.token; @@ -53,8 +54,8 @@ export default async function xteveProxyHandler(req, res) { }); if (status !== 200) { - logger.debug("Error %d calling endpoint %s", status, url); - return res.status(status, data); + logger.debug("Error %d calling xteve endpoint %s", status, url); + return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}}); } if (contentType) res.setHeader("Content-Type", contentType);