From 0741284424fe9e0cc0df427c07f6028d19615536 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 7 Sep 2024 10:50:57 -0700 Subject: [PATCH] Add some wg-easy logging --- src/widgets/wgeasy/proxy.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/widgets/wgeasy/proxy.js b/src/widgets/wgeasy/proxy.js index 53c646e22..b7dfc99ad 100644 --- a/src/widgets/wgeasy/proxy.js +++ b/src/widgets/wgeasy/proxy.js @@ -12,7 +12,7 @@ const sessionSIDCacheKey = `${proxyName}__sessionSID`; async function login(widget, service) { const url = formatApiCall(widgets[widget.type].api, { ...widget, endpoint: "session" }); - const [, , , responseHeaders] = await httpProxy(url, { + const [statusCode, , , responseHeaders] = await httpProxy(url, { method: "POST", body: JSON.stringify({ password: widget.password }), headers: { @@ -20,7 +20,15 @@ async function login(widget, service) { }, }); + if (statusCode > 400) { + logger.error( + `Failed to login to wg-easy, statusCode: ${statusCode}, responseHeaders: ${JSON.stringify(responseHeaders)}`, + ); + return null; + } + try { + logger.debug(`Logging into wg-easy, responseHeaders: ${JSON.stringify(responseHeaders)}`); let connectSidCookie = responseHeaders["set-cookie"]; if (!connectSidCookie) { const sid = cache.get(`${sessionSIDCacheKey}.${service}`); @@ -35,7 +43,7 @@ async function login(widget, service) { cache.put(`${sessionSIDCacheKey}.${service}`, connectSidCookie); return connectSidCookie; } catch (e) { - logger.error(`Error logging into wg-easy, error: ${e}`); + logger.error(`Error logging into wg-easy: ${JSON.stringify(e)}`); cache.del(`${sessionSIDCacheKey}.${service}`); return null; } @@ -56,7 +64,7 @@ export default async function wgeasyProxyHandler(req, res) { if (!sid) { sid = await login(widget, service); if (!sid) { - return res.status(500).json({ error: "Failed to authenticate with Wg-Easy" }); + return res.status(500).json({ error: "Failed to authenticate with Wg-Easy. See logs for more details." }); } } const [, , data] = await httpProxy(