mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 05:25:53 +08:00
refactor(core): standardize frontend error handling (#10667)
This commit is contained in:
+2
-2
@@ -11,7 +11,7 @@ import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
|
||||
import { OpenInAppService } from '@affine/core/modules/open-in-app';
|
||||
import { GuardService } from '@affine/core/modules/permissions';
|
||||
import { WorkspaceService } from '@affine/core/modules/workspace';
|
||||
import { UserFriendlyError } from '@affine/graphql';
|
||||
import { UserFriendlyError } from '@affine/error';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { track } from '@affine/track';
|
||||
import {
|
||||
@@ -87,7 +87,7 @@ export function useRegisterBlocksuiteEditorCommands(
|
||||
doc.moveToTrash();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
const userFriendlyError = UserFriendlyError.fromAnyError(error);
|
||||
const userFriendlyError = UserFriendlyError.fromAny(error);
|
||||
toast(t[`error.${userFriendlyError.name}`](userFriendlyError.data));
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { notify } from '@affine/component';
|
||||
import { GraphQLError } from '@affine/graphql';
|
||||
import { UserFriendlyError } from '@affine/error';
|
||||
import type { PropsWithChildren, ReactNode } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import type { SWRConfiguration } from 'swr';
|
||||
@@ -17,21 +17,13 @@ const swrConfig: SWRConfiguration = {
|
||||
const d = fetcher(...args);
|
||||
if (d instanceof Promise) {
|
||||
return d.catch(e => {
|
||||
if (
|
||||
e instanceof GraphQLError ||
|
||||
(Array.isArray(e) && e[0] instanceof GraphQLError)
|
||||
) {
|
||||
const graphQLError = e instanceof GraphQLError ? e : e[0];
|
||||
notify.error({
|
||||
title: 'GraphQL Error',
|
||||
message: graphQLError.toString(),
|
||||
});
|
||||
} else {
|
||||
notify.error({
|
||||
title: 'Error',
|
||||
message: e.toString(),
|
||||
});
|
||||
}
|
||||
const error = UserFriendlyError.fromAny(e);
|
||||
|
||||
notify.error({
|
||||
title: error.name,
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { DocsService } from '@affine/core/modules/doc';
|
||||
import { GlobalContextService } from '@affine/core/modules/global-context';
|
||||
import { GuardService } from '@affine/core/modules/permissions';
|
||||
import type { AffineDNDData } from '@affine/core/types/dnd';
|
||||
import { UserFriendlyError } from '@affine/graphql';
|
||||
import { UserFriendlyError } from '@affine/error';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
|
||||
@@ -58,8 +58,7 @@ export const TrashButton = () => {
|
||||
docRecord.moveToTrash();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
const userFriendlyError =
|
||||
UserFriendlyError.fromAnyError(error);
|
||||
const userFriendlyError = UserFriendlyError.fromAny(error);
|
||||
toast(
|
||||
t[`error.${userFriendlyError.name}`](userFriendlyError.data)
|
||||
);
|
||||
|
||||
@@ -8,13 +8,10 @@ import {
|
||||
} from '@affine/component/auth-components';
|
||||
import { Button } from '@affine/component/ui/button';
|
||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||
import {
|
||||
AuthService,
|
||||
BackendError,
|
||||
CaptchaService,
|
||||
} from '@affine/core/modules/cloud';
|
||||
import { AuthService, CaptchaService } from '@affine/core/modules/cloud';
|
||||
import type { AuthSessionStatus } from '@affine/core/modules/cloud/entities/session';
|
||||
import { Unreachable } from '@affine/env/constant';
|
||||
import type { UserFriendlyError } from '@affine/error';
|
||||
import { Trans, useI18n } from '@affine/i18n';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import {
|
||||
@@ -143,12 +140,10 @@ export const SignInWithEmailStep = ({
|
||||
try {
|
||||
await authService.signInMagicLink(email, otp, false);
|
||||
} catch (e) {
|
||||
if (e instanceof BackendError) {
|
||||
notify.error({
|
||||
title: e.originError.message,
|
||||
});
|
||||
setOtpError(t['com.affine.auth.sign.auth.code.invalid']());
|
||||
}
|
||||
notify.error({
|
||||
title: (e as UserFriendlyError).message,
|
||||
});
|
||||
setOtpError(t['com.affine.auth.sign.auth.code.invalid']());
|
||||
} finally {
|
||||
setIsVerifying(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user