adds try/catch to API key validation

This commit is contained in:
kevmodrome 2020-12-16 11:35:12 +01:00
parent b582b7ac22
commit 8ce3aab2a7
2 changed files with 15 additions and 12 deletions

View File

@ -39,10 +39,10 @@ function identify(id) {
async function identifyByApiKey(apiKey) { async function identifyByApiKey(apiKey) {
if (!analyticsEnabled) return true if (!analyticsEnabled) return true
try {
const response = await fetch( const response = await fetch(
`https://03gaine137.execute-api.eu-west-1.amazonaws.com/prod/account/id?api_key=${apiKey.trim()}` `https://03gaine137.execute-api.eu-west-1.amazonaws.com/prod/account/id?api_key=${apiKey.trim()}`
) )
if (response.status === 200) { if (response.status === 200) {
const id = await response.json() const id = await response.json()
@ -52,6 +52,10 @@ async function identifyByApiKey(apiKey) {
} }
return false return false
} catch (error) {
console.log(error)
}
} }
function captureException(err) { function captureException(err) {

View File

@ -27,7 +27,6 @@
// make sure we only fetch once, unless API Key is changed // make sure we only fetch once, unless API Key is changed
if (isApiKeyValid === undefined || apiKey !== lastApiKey) { if (isApiKeyValid === undefined || apiKey !== lastApiKey) {
lastApiKey = apiKey
// svelte reactivity was causing a requst to get fired mutiple times // svelte reactivity was causing a requst to get fired mutiple times
// so, we make everything await the same promise, if one exists // so, we make everything await the same promise, if one exists
if (!fetchApiKeyPromise) { if (!fetchApiKeyPromise) {