From 6f1535014dfab6162bb600f70a8524d7627c4dd1 Mon Sep 17 00:00:00 2001 From: darkskygit Date: Tue, 22 Oct 2024 05:08:10 +0000 Subject: [PATCH] feat(core): handle copilot errors (#8546) --- .../src/blocksuite/presets/ai/provider.ts | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/frontend/core/src/blocksuite/presets/ai/provider.ts b/packages/frontend/core/src/blocksuite/presets/ai/provider.ts index 9ddcbd5e1273d..bb7d801b2d5e9 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/provider.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/provider.ts @@ -4,6 +4,7 @@ import { UnauthorizedError, } from '@blocksuite/affine/blocks'; import { Slot } from '@blocksuite/affine/store'; +import { captureException } from '@sentry/react'; export interface AIUserInfo { id: string; @@ -171,7 +172,9 @@ export class AIProvider { if (isTextStream(result)) { return { [Symbol.asyncIterator]: async function* () { + let user = null; try { + user = await AIProvider.userInfo; yield* result; slots.actions.emit({ action: id, @@ -202,14 +205,23 @@ export class AIProvider { options, event: 'aborted:server-error', }); + captureException(err, { + user: { id: user?.id }, + extra: { + action: id, + session: AIProvider.LAST_ACTION_SESSIONID, + }, + }); } throw err; } }, }; } else { + let user: any = null; return result - .then(result => { + .then(async result => { + user = await AIProvider.userInfo; slots.actions.emit({ action: id, options, @@ -229,6 +241,14 @@ export class AIProvider { options, event: 'aborted:paywall', }); + } else { + captureException(err, { + user: { id: user?.id }, + extra: { + action: id, + session: AIProvider.LAST_ACTION_SESSIONID, + }, + }); } throw err; });