refactor(core): standardize frontend error handling (#10667)

This commit is contained in:
forehalo
2025-03-06 13:10:18 +00:00
parent 2e86bfffae
commit e02fb4fa94
70 changed files with 495 additions and 480 deletions
@@ -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) {