fix: 🐛 Update validateOrigin to throw error on bad request (#1107)

* 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 <zhihe.li@hashicorp.com>

* 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 <randall@randallmorey.com>

* Update ui/desktop/electron-app/src/models/runtime-settings.js

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
Co-authored-by: Randall Morey <randall@randallmorey.com>
This commit is contained in:
authored and GitHub committed 2022-05-16 12:20:56 -05:00
1 parent ee47f8e19e
commit aa52b6f9bc
1 file changed
+6 -1
@@ -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.`);
}