diff --git a/packages/frontend/core/src/components/sign-in/sign-in-with-password.tsx b/packages/frontend/core/src/components/sign-in/sign-in-with-password.tsx index 33dc21c43b6b4..2d04e1c68a858 100644 --- a/packages/frontend/core/src/components/sign-in/sign-in-with-password.tsx +++ b/packages/frontend/core/src/components/sign-in/sign-in-with-password.tsx @@ -9,7 +9,6 @@ import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hoo import { AuthService, CaptchaService, - isBackendError, ServerService, } from '@affine/core/modules/cloud'; import { Unreachable } from '@affine/env/constant'; @@ -91,15 +90,11 @@ export const SignInWithPasswordStep = ({ }); } catch (err) { console.error(err); - if ( - err instanceof Error && - isBackendError(err) && - UserFriendlyError.fromAnyError(err).name === - ErrorNames.UNSUPPORTED_CLIENT_VERSION - ) { - const { action } = UserFriendlyError.fromAnyError(err).args; + const userFriendlyError = UserFriendlyError.fromAnyError(err); + if (userFriendlyError.name === ErrorNames.UNSUPPORTED_CLIENT_VERSION) { + const { action } = userFriendlyError.args; nav( - `/sign-in?error=${encodeURIComponent(err.message)}&action=${encodeURIComponent(action as string)}` + `/sign-in?error=${encodeURIComponent(userFriendlyError.message)}&action=${encodeURIComponent(action as string)}` ); return; } diff --git a/packages/frontend/core/src/desktop/pages/auth/magic-link.tsx b/packages/frontend/core/src/desktop/pages/auth/magic-link.tsx index 1587b03c7b547..3e4c007826116 100644 --- a/packages/frontend/core/src/desktop/pages/auth/magic-link.tsx +++ b/packages/frontend/core/src/desktop/pages/auth/magic-link.tsx @@ -9,7 +9,7 @@ import { useNavigate, } from 'react-router-dom'; -import { AuthService, isBackendError } from '../../../modules/cloud'; +import { AuthService } from '../../../modules/cloud'; import { supportedClient } from './common'; interface LoaderData { @@ -80,15 +80,11 @@ export const Component = () => { }); }) .catch(err => { - if ( - err instanceof Error && - isBackendError(err) && - UserFriendlyError.fromAnyError(err).name === - ErrorNames.UNSUPPORTED_CLIENT_VERSION - ) { - const { action } = UserFriendlyError.fromAnyError(err).args; + const userFriendlyError = UserFriendlyError.fromAnyError(err); + if (userFriendlyError.name === ErrorNames.UNSUPPORTED_CLIENT_VERSION) { + const { action } = userFriendlyError.args; nav( - `/sign-in?error=${encodeURIComponent(err.message)}&action=${encodeURIComponent(action as string)}` + `/sign-in?error=${encodeURIComponent(userFriendlyError.message)}&action=${encodeURIComponent(action as string)}` ); return; } diff --git a/packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx b/packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx index b2df33351ac01..31e734246fce9 100644 --- a/packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx +++ b/packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx @@ -9,7 +9,7 @@ import { useNavigate, } from 'react-router-dom'; -import { AuthService, isBackendError } from '../../../modules/cloud'; +import { AuthService } from '../../../modules/cloud'; import { supportedClient } from './common'; interface LoaderData { @@ -82,15 +82,11 @@ export const Component = () => { nav(redirectUri ?? '/'); }) .catch(err => { - if ( - err instanceof Error && - isBackendError(err) && - UserFriendlyError.fromAnyError(err).name === - ErrorNames.UNSUPPORTED_CLIENT_VERSION - ) { - const { action } = UserFriendlyError.fromAnyError(err).args; + const userFriendlyError = UserFriendlyError.fromAnyError(err); + if (userFriendlyError.name === ErrorNames.UNSUPPORTED_CLIENT_VERSION) { + const { action } = userFriendlyError.args; nav( - `/sign-in?error=${encodeURIComponent(err.message)}&action=${encodeURIComponent(action as string)}` + `/sign-in?error=${encodeURIComponent(userFriendlyError.message)}&action=${encodeURIComponent(action as string)}` ); return; }