Skip to content

Commit 3977711

Browse files
haha1903Hai Chang
and
Hai Chang
authored
feat: Improve OpenAI API integration and response handling (#5)
Co-authored-by: Hai Chang <haichang@microsoft.com>
1 parent f330d9b commit 3977711

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/app.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export class ChatController {
3737
stream,
3838
);
3939

40+
if (response.status > 299 || response.status < 200) {
41+
res.status(response.status);
42+
res.send(response.data);
43+
return;
44+
}
45+
4046
// set response headers
4147
for (const [key, value] of response.headers as AxiosHeaders) {
4248
res.header[key] = value;

src/app.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export class AppService {
3636
config['responseType'] = 'stream';
3737
}
3838
const ret = this.httpService.post(url, body, config);
39-
return await firstValueFrom(ret);
39+
try {
40+
return await firstValueFrom(ret);
41+
} catch (e) {
42+
return e.response;
43+
}
4044
}
4145
private getDeploymentId(mapping: string, model: string): string {
4246
this.logger.debug(`mapping: ${mapping}, model: ${model}`);

0 commit comments

Comments
 (0)