From 94e56ee94df6916c6c8b500508c98d84fad321e9 Mon Sep 17 00:00:00 2001 From: kevmodrome Date: Wed, 16 Dec 2020 11:35:12 +0100 Subject: [PATCH] adds try/catch to API key validation --- packages/builder/src/analytics.js | 26 +++++++++++-------- .../components/start/CreateAppModal.svelte | 1 - 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/analytics.js b/packages/builder/src/analytics.js index a7166f00f6..10d67addb3 100644 --- a/packages/builder/src/analytics.js +++ b/packages/builder/src/analytics.js @@ -39,19 +39,23 @@ function identify(id) { async function identifyByApiKey(apiKey) { if (!analyticsEnabled) return true - const response = await fetch( - `https://03gaine137.execute-api.eu-west-1.amazonaws.com/prod/account/id?api_key=${apiKey.trim()}` - ) - - if (response.status === 200) { - const id = await response.json() - - await api.put("/api/keys/userId", { value: id }) - identify(id) - return true + try { + const response = await fetch( + `https://03gaine137.execute-api.eu-west-1.amazonaws.com/prod/account/id?api_key=${apiKey.trim()}` + ) + if (response.status === 200) { + const id = await response.json() + + await api.put("/api/keys/userId", { value: id }) + identify(id) + return true + } + + return false + } catch (error) { + console.log(error) } - return false } function captureException(err) { diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index b88397b6c4..184eaeb2d6 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -27,7 +27,6 @@ // make sure we only fetch once, unless API Key is changed if (isApiKeyValid === undefined || apiKey !== lastApiKey) { - lastApiKey = apiKey // svelte reactivity was causing a requst to get fired mutiple times // so, we make everything await the same promise, if one exists if (!fetchApiKeyPromise) {