feat(core): handle copilot errors (#8546)

This commit is contained in:
darkskygit
2024-10-22 05:08:10 +00:00
parent b8cb504fa4
commit 6f1535014d

View File

@@ -4,6 +4,7 @@ import {
UnauthorizedError, UnauthorizedError,
} from '@blocksuite/affine/blocks'; } from '@blocksuite/affine/blocks';
import { Slot } from '@blocksuite/affine/store'; import { Slot } from '@blocksuite/affine/store';
import { captureException } from '@sentry/react';
export interface AIUserInfo { export interface AIUserInfo {
id: string; id: string;
@@ -171,7 +172,9 @@ export class AIProvider {
if (isTextStream(result)) { if (isTextStream(result)) {
return { return {
[Symbol.asyncIterator]: async function* () { [Symbol.asyncIterator]: async function* () {
let user = null;
try { try {
user = await AIProvider.userInfo;
yield* result; yield* result;
slots.actions.emit({ slots.actions.emit({
action: id, action: id,
@@ -202,14 +205,23 @@ export class AIProvider {
options, options,
event: 'aborted:server-error', event: 'aborted:server-error',
}); });
captureException(err, {
user: { id: user?.id },
extra: {
action: id,
session: AIProvider.LAST_ACTION_SESSIONID,
},
});
} }
throw err; throw err;
} }
}, },
}; };
} else { } else {
let user: any = null;
return result return result
.then(result => { .then(async result => {
user = await AIProvider.userInfo;
slots.actions.emit({ slots.actions.emit({
action: id, action: id,
options, options,
@@ -229,6 +241,14 @@ export class AIProvider {
options, options,
event: 'aborted:paywall', event: 'aborted:paywall',
}); });
} else {
captureException(err, {
user: { id: user?.id },
extra: {
action: id,
session: AIProvider.LAST_ACTION_SESSIONID,
},
});
} }
throw err; throw err;
}); });