From c0f857336ad4d43729a3f9442d4a23b4ae0e2198 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 5 Dec 2018 21:34:02 -0800 Subject: [PATCH] fix: error msg when logging in to same instance (#735) --- routes/_actions/addInstance.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/routes/_actions/addInstance.js b/routes/_actions/addInstance.js index ee17022..ffa24b5 100644 --- a/routes/_actions/addInstance.js +++ b/routes/_actions/addInstance.js @@ -14,8 +14,9 @@ async function redirectToOauth () { let { instanceNameInSearch, loggedInInstances } = store.get() instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase() if (Object.keys(loggedInInstances).includes(instanceNameInSearch)) { - store.set({ logInToInstanceError: `You've already logged in to ${instanceNameInSearch}` }) - return + let err = new Error(`You've already logged in to ${instanceNameInSearch}`) + err.knownError = true + throw err } let registrationPromise = registerApplication(instanceNameInSearch, REDIRECT_URI) let instanceInfo = await getInstanceInfo(instanceNameInSearch) @@ -44,10 +45,10 @@ export async function logInToInstance () { } catch (err) { console.error(err) let error = `${err.message || err.name}. ` + - (navigator.onLine + (err.knownError ? '' : (navigator.onLine ? `Is this a valid Mastodon instance? Is a browser extension blocking the request? Are you in private browsing mode?` - : `Are you offline?`) + : `Are you offline?`)) let { instanceNameInSearch } = store.get() store.set({ logInToInstanceError: error,