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,
} 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;
});