Skip to content

Commit 4d6cd77

Browse files
committed
feat: Improve chat completions route with async handling and error logging
1 parent 100c9a3 commit 4d6cd77

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/routes/chat-completions/route.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ import { handlerStreaming } from "./handler-streaming"
99

1010
export const completionRoutes = new Hono()
1111

12-
completionRoutes.post("/chat/completions", (c) => {
12+
completionRoutes.post("/chat/completions", async (c) => {
1313
try {
1414
if (ENV.EMULATE_STREAMING) {
15-
return handler(c)
16-
} else {
17-
return handlerStreaming(c)
15+
return await handler(c)
1816
}
17+
18+
return await handlerStreaming(c)
1919
} catch (error) {
2020
if (error instanceof FetchError) {
2121
consola.error(`Request failed: ${error.message}`, error.response?._data)
22+
} else {
23+
consola.error("Error:", error)
2224
}
23-
consola.error(error)
2425

2526
throw error
2627
}

0 commit comments

Comments
 (0)