Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit f6e667f

Browse files
authored
chore: error handling for chat/completions endpoint (#793)
1 parent 3704025 commit f6e667f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cortex-js/src/infrastructure/controllers/chat.controller.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,25 @@ export class ChatController {
2929
const { stream } = createChatDto;
3030

3131
if (stream) {
32-
res.header('Content-Type', 'text/event-stream');
3332
this.chatService
3433
.inference(createChatDto, headers)
35-
.then((stream) => stream.pipe(res));
34+
.then((stream) => {
35+
res.header('Content-Type', 'text/event-stream');
36+
stream.pipe(res);
37+
})
38+
.catch((error) =>
39+
res.status(error.statusCode ?? 400).send(error.message),
40+
);
3641
} else {
3742
res.header('Content-Type', 'application/json');
38-
res.json(await this.chatService.inference(createChatDto, headers));
43+
this.chatService
44+
.inference(createChatDto, headers)
45+
.then((response) => {
46+
res.json(response);
47+
})
48+
.catch((error) =>
49+
res.status(error.statusCode ?? 400).send(error.message),
50+
);
3951
}
4052
}
4153
}

0 commit comments

Comments
 (0)