Skip to content

Commit

Permalink
feat(core): handle copilot errors (#8546)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Oct 22, 2024
1 parent b8cb504 commit 6f15350
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/frontend/core/src/blocksuite/presets/ai/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
});
Expand Down

0 comments on commit 6f15350

Please sign in to comment.