From aa52b6f9bc73f6995d5f6140301cb8abf640f3b7 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Mon, 16 May 2022 12:20:56 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Update=20validateOrigin?= =?UTF-8?q?=20to=20throw=20error=20on=20bad=20request=20(#1107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 Update validateOrigin to throw error on bad request If the result from netRequestPromise is successful but a not a 200 response, validateOrigin will throw an error ✅ Closes: ICU-4238 * Update ui/desktop/electron-app/src/models/runtime-settings.js Co-authored-by: Zhihe Li * refactor: 💡 Add comment as to why we don't throw error for 3xxs * Update ui/desktop/electron-app/src/models/runtime-settings.js Co-authored-by: Randall Morey * Update ui/desktop/electron-app/src/models/runtime-settings.js Co-authored-by: Zhihe Li Co-authored-by: Zhihe Li Co-authored-by: Randall Morey --- ui/desktop/electron-app/src/models/runtime-settings.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/desktop/electron-app/src/models/runtime-settings.js b/ui/desktop/electron-app/src/models/runtime-settings.js index fdd91608c..eb821985d 100644 --- a/ui/desktop/electron-app/src/models/runtime-settings.js +++ b/ui/desktop/electron-app/src/models/runtime-settings.js @@ -31,7 +31,12 @@ class RuntimeSettings { // test to see if the origin is API-compatible with the desktop client. const scopesEndpoint = `${origin}/v1/scopes`; try { - await netRequestPromise(scopesEndpoint); + const result = await netRequestPromise(scopesEndpoint); + // Redirects (3xx) are handled in the netRequest Promise, so we only + // throw an error for 4xx or 5xx responses. + if (result.statusCode >= 400) { + throw new Error(); + } } catch (e) { throw new Error(`Origin ${origin} could not be validated.`); }