mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 15:46:29 +08:00
fix: ai error handling (#6588)
upstream: https://github.com/toeverything/blocksuite/pull/6775
This commit is contained in:
+17
-1
@@ -1,17 +1,33 @@
|
||||
import {
|
||||
createCopilotMessageMutation,
|
||||
createCopilotSessionMutation,
|
||||
fetcher,
|
||||
fetcher as defaultFetcher,
|
||||
getBaseUrl,
|
||||
getCopilotHistoriesQuery,
|
||||
getCopilotSessionsQuery,
|
||||
type GraphQLQuery,
|
||||
type QueryOptions,
|
||||
type RequestOptions,
|
||||
} from '@affine/graphql';
|
||||
import { GeneralNetworkError, PaymentRequiredError } from '@blocksuite/blocks';
|
||||
|
||||
type OptionsField<T extends GraphQLQuery> =
|
||||
RequestOptions<T>['variables'] extends { options: infer U } ? U : never;
|
||||
|
||||
const fetcher = async <Query extends GraphQLQuery>(
|
||||
options: QueryOptions<Query>
|
||||
) => {
|
||||
try {
|
||||
return await defaultFetcher<Query>(options);
|
||||
} catch (_err) {
|
||||
const error = Array.isArray(_err) ? _err.at(0) : _err;
|
||||
if (error.extensions?.code === 402) {
|
||||
throw new PaymentRequiredError();
|
||||
}
|
||||
throw new GeneralNetworkError();
|
||||
}
|
||||
};
|
||||
|
||||
export class CopilotClient {
|
||||
readonly backendUrl = getBaseUrl();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { openSettingModalAtom } from '@affine/core/atoms';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { AIProvider } from '@blocksuite/presets';
|
||||
import { getCurrentStore } from '@toeverything/infra';
|
||||
|
||||
import type { PromptKey } from './prompt';
|
||||
import {
|
||||
@@ -263,4 +265,11 @@ export function setupAIProvider() {
|
||||
forceToImage: true,
|
||||
});
|
||||
});
|
||||
|
||||
AIProvider.slots.requestUpgradePlan.on(() => {
|
||||
getCurrentStore().set(openSettingModalAtom, {
|
||||
activeTab: 'billing',
|
||||
open: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user