diff --git a/desktop/app/src/reducers/user.tsx b/desktop/app/src/reducers/user.tsx index 72248336f..967e84074 100644 --- a/desktop/app/src/reducers/user.tsx +++ b/desktop/app/src/reducers/user.tsx @@ -9,9 +9,6 @@ import {Actions} from './'; -export const USER_UNAUTHORIZED = 'Unauthorized.'; -export const USER_NOT_SIGNEDIN = 'Not signed in.'; - export type User = { id?: string; name?: string; diff --git a/desktop/app/src/sandy-chrome/LeftRail.tsx b/desktop/app/src/sandy-chrome/LeftRail.tsx index ede357d54..a14a1daf3 100644 --- a/desktop/app/src/sandy-chrome/LeftRail.tsx +++ b/desktop/app/src/sandy-chrome/LeftRail.tsx @@ -43,7 +43,7 @@ import SignInSheet from '../chrome/fb-stubs/SignInSheet'; import {errorCounterAtom} from '../chrome/ConsoleLogs'; import {ToplevelProps} from './SandyApp'; import {useValue} from 'flipper-plugin'; -import {logout, USER_NOT_SIGNEDIN, USER_UNAUTHORIZED} from '../reducers/user'; +import {logout} from '../reducers/user'; import config from '../fb-stubs/config'; import styled from '@emotion/styled'; import {showEmulatorLauncher} from './appinspect/LaunchEmulator'; @@ -58,6 +58,7 @@ import isProduction from '../utils/isProduction'; import NetworkGraph from '../chrome/NetworkGraph'; import FpsGraph from '../chrome/FpsGraph'; import UpdateIndicator from '../chrome/UpdateIndicator'; +import {UserNotSignedInError, UserUnauthorizedError} from '../utils/errors'; const LeftRailButtonElem = styled(Button)<{kind?: 'small'}>(({kind}) => ({ width: kind === 'small' ? 32 : 36, @@ -380,7 +381,10 @@ function LoginButton() { useEffect(() => { if (config.showLogin) { getUser().catch((error) => { - if (error === USER_UNAUTHORIZED || error === USER_NOT_SIGNEDIN) { + if ( + error instanceof UserUnauthorizedError || + error instanceof UserNotSignedInError + ) { setShowLogin(true); } }); diff --git a/desktop/app/src/utils/errors.tsx b/desktop/app/src/utils/errors.tsx index 7aa0dae7a..527ef2bde 100644 --- a/desktop/app/src/utils/errors.tsx +++ b/desktop/app/src/utils/errors.tsx @@ -17,6 +17,22 @@ export class CancelledPromiseError extends Error { name: 'CancelledPromiseError'; } +export class UserUnauthorizedError extends Error { + constructor(msg: string = 'User unauthorized.') { + super(msg); + this.name = 'UserUnauthorizedError'; + } + name: 'UserUnauthorizedError'; +} + +export class UserNotSignedInError extends Error { + constructor(msg: string = 'User not signed in.') { + super(msg); + this.name = 'UserNotSignedInError'; + } + name: 'UserNotSignedInError'; +} + declare global { interface Error { interaction?: InteractionReport;