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