Handle thrown errors much better
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import {useCallback} from 'react'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {useAnalytics} from '#/lib/analytics/analytics'
|
||||
import {useSessionApi, SessionAccount} from '#/state/session'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
import {logger} from '#/logger'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {SessionAccount, useSessionApi} from '#/state/session'
|
||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {LogEvents} from '../statsig/statsig'
|
||||
|
||||
export function useAccountSwitcher() {
|
||||
@@ -44,9 +45,14 @@ export function useAccountSwitcher() {
|
||||
'circle-exclamation',
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
Toast.show('Sorry! We need you to enter your password.')
|
||||
} catch (e: any) {
|
||||
logger.error(`switch account: selectAccount failed`, {
|
||||
message: e.message,
|
||||
})
|
||||
clearCurrentAccount() // back user out to login
|
||||
setTimeout(() => {
|
||||
Toast.show('Sorry! We need you to enter your password.')
|
||||
}, 100)
|
||||
}
|
||||
},
|
||||
[
|
||||
|
||||
@@ -5,6 +5,7 @@ import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useAnalytics} from '#/lib/analytics/analytics'
|
||||
import {logEvent} from '#/lib/statsig/statsig'
|
||||
import {logger} from '#/logger'
|
||||
import {SessionAccount, useSession, useSessionApi} from '#/state/session'
|
||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
@@ -38,15 +39,22 @@ export const ChooseAccountForm = ({
|
||||
setShowLoggedOut(false)
|
||||
Toast.show(_(msg`Already signed in as @${account.handle}`))
|
||||
} else {
|
||||
await initSession(account)
|
||||
logEvent('account:loggedIn', {
|
||||
logContext: 'ChooseAccountForm',
|
||||
withPassword: false,
|
||||
})
|
||||
track('Sign In', {resumedSession: true})
|
||||
setTimeout(() => {
|
||||
Toast.show(_(msg`Signed in as @${account.handle}`))
|
||||
}, 100)
|
||||
try {
|
||||
await initSession(account)
|
||||
logEvent('account:loggedIn', {
|
||||
logContext: 'ChooseAccountForm',
|
||||
withPassword: false,
|
||||
})
|
||||
track('Sign In', {resumedSession: true})
|
||||
setTimeout(() => {
|
||||
Toast.show(_(msg`Signed in as @${account.handle}`))
|
||||
}, 100)
|
||||
} catch (e: any) {
|
||||
logger.error('choose account: initSession failed', {
|
||||
message: e.message,
|
||||
})
|
||||
onSelectAccount(account)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
onSelectAccount(account)
|
||||
|
||||
@@ -213,6 +213,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
console.log('PERSIST', window.__id, {
|
||||
event,
|
||||
refreshJwt: session?.refreshJwt?.slice(-10),
|
||||
agent: agent.session?.refreshJwt.slice(-10),
|
||||
})
|
||||
|
||||
const expired = event === 'expired' || event === 'create-failed'
|
||||
@@ -226,7 +227,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
return
|
||||
}
|
||||
|
||||
agent.session = session
|
||||
const refreshedAccount = agentToSessionAccount(agent)
|
||||
|
||||
if (!refreshedAccount) {
|
||||
@@ -414,19 +414,12 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
{},
|
||||
logger.DebugContext.session,
|
||||
)
|
||||
try {
|
||||
// will call `persistSession` on `BskyAgent` instance above if success
|
||||
await networkRetry(1, () => agent.resumeSession(prevSession))
|
||||
setCurrentAgent(agent)
|
||||
} catch (e) {
|
||||
// this can fail on bad connections as well, so `clearCurrentAccount`
|
||||
// bumps them out to login, but doesn't rug tokens
|
||||
logger.error(`session: resumeSession failed`, {message: e})
|
||||
clearCurrentAccount()
|
||||
}
|
||||
// will call `persistSession` on `BskyAgent` instance above if success
|
||||
await networkRetry(1, () => agent.resumeSession(prevSession))
|
||||
setCurrentAgent(agent)
|
||||
}
|
||||
},
|
||||
[upsertAndPersistAccount, clearCurrentAccount, persistSession],
|
||||
[upsertAndPersistAccount, persistSession],
|
||||
)
|
||||
|
||||
const resumeSession = React.useCallback<ApiContext['resumeSession']>(
|
||||
|
||||
Reference in New Issue
Block a user