From 9ede44b12d5b6e7ca494c72cebab4a80c9d9ac0e Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:12:53 -0700 Subject: [PATCH] Fix: properly handle wg-easy errors (#3849) Also reverts #3768 --- src/widgets/wgeasy/component.jsx | 2 +- src/widgets/wgeasy/proxy.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/widgets/wgeasy/component.jsx b/src/widgets/wgeasy/component.jsx index 1b3e0196..624002c4 100644 --- a/src/widgets/wgeasy/component.jsx +++ b/src/widgets/wgeasy/component.jsx @@ -15,7 +15,7 @@ export default function Component({ service }) { return <Container service={service} error={infoError} />; } - if (!infoData || infoData.errorCode) { + if (!infoData) { return ( <Container service={service}> <Block label="wgeasy.connected" /> diff --git a/src/widgets/wgeasy/proxy.js b/src/widgets/wgeasy/proxy.js index d4289dc6..53c646e2 100644 --- a/src/widgets/wgeasy/proxy.js +++ b/src/widgets/wgeasy/proxy.js @@ -69,7 +69,15 @@ export default async function wgeasyProxyHandler(req, res) { }, ); - return res.json(JSON.parse(data)); + const parsedData = JSON.parse(data); + + if (parsedData.statusCode > 400) { + return res + .status(parsedData.statusCode) + .json({ error: { message: "Error communicating with Wg-Easy", data: parsedData } }); + } + + return res.json(parsedData); } }