Skip to content

Commit

Permalink
chore: handle quota error
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Apr 23, 2024
1 parent ed957b9 commit 48f11ab
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/backend/server/src/plugins/copilot/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,10 @@ export class CopilotController {
if (err instanceof Error) {
const ret = {
message: err.message,
cause: {
status: (err as any).status,
...(typeof err.cause === 'object' && !!err.cause ? err.cause : {}),
},
status: (err as any).status,
};
if (err instanceof HttpException) {
ret.cause.status = err.getStatus();
ret.status = err.getStatus();
}
}
return err;
Expand Down Expand Up @@ -157,7 +154,14 @@ export class CopilotController {
@Query('messageId') messageId: string,
@Query() params: Record<string, string>
): Promise<Observable<ChatEvent>> {
await this.chatSession.checkQuota(user.id);
try {
await this.chatSession.checkQuota(user.id);
} catch (err) {
return of({
type: 'error' as const,
data: this.handleError(err),
});
}

const model = await this.chatSession.get(sessionId).then(s => s?.model);
const provider = this.provider.getProviderByCapability(
Expand Down Expand Up @@ -215,7 +219,14 @@ export class CopilotController {
@Query('messageId') messageId: string,
@Query() params: Record<string, string>
): Promise<Observable<ChatEvent>> {
await this.chatSession.checkQuota(user.id);
try {
await this.chatSession.checkQuota(user.id);
} catch (err) {
return of({
type: 'error' as const,
data: this.handleError(err),
});
}

const hasAttachment = await this.hasAttachment(sessionId, messageId);
const model = await this.chatSession.get(sessionId).then(s => s?.model);
Expand Down

0 comments on commit 48f11ab

Please sign in to comment.