mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 21:48:48 +08:00
refactor(core): standardize frontend error handling (#10667)
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
UnauthorizedError,
|
||||
} from '@affine/core/blocksuite/ai/components/ai-item/types';
|
||||
import { showAILoginRequiredAtom } from '@affine/core/components/affine/auth/ai-login-required';
|
||||
import type { UserFriendlyError } from '@affine/error';
|
||||
import {
|
||||
addContextDocMutation,
|
||||
cleanupCopilotSessionMutation,
|
||||
@@ -14,7 +15,6 @@ import {
|
||||
getCopilotHistoriesQuery,
|
||||
getCopilotHistoryIdsQuery,
|
||||
getCopilotSessionsQuery,
|
||||
GraphQLError,
|
||||
type GraphQLQuery,
|
||||
listContextDocsAndFilesQuery,
|
||||
listContextQuery,
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
removeContextDocMutation,
|
||||
type RequestOptions,
|
||||
updateCopilotSessionMutation,
|
||||
UserFriendlyError,
|
||||
} from '@affine/graphql';
|
||||
import { getCurrentStore } from '@toeverything/infra';
|
||||
|
||||
@@ -40,18 +39,13 @@ function codeToError(error: UserFriendlyError) {
|
||||
return new GeneralNetworkError(
|
||||
error.code
|
||||
? `${error.code}: ${error.message}\nIdentify: ${error.name}`
|
||||
: undefined
|
||||
: error.message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveError(err: any) {
|
||||
const standardError =
|
||||
err instanceof GraphQLError
|
||||
? new UserFriendlyError(err.extensions)
|
||||
: UserFriendlyError.fromAnyError(err);
|
||||
|
||||
return codeToError(standardError);
|
||||
return codeToError(err);
|
||||
}
|
||||
|
||||
export function handleError(src: any) {
|
||||
|
||||
Reference in New Issue
Block a user