File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1+ // VSCode client ID
12const GITHUB_CLIENT_ID = "01ab8ac9400c4e429b23"
23const GITHUB_OAUTH_SCOPES = [
34 "read:org" ,
Original file line number Diff line number Diff line change 1+ import consola from "consola"
12import { Hono } from "hono"
23import { streamSSE } from "hono/streaming"
4+ import { FetchError } from "ofetch"
35
46import type { ChatCompletionsPayload } from "~/services/copilot-vscode/chat-completions/types"
57import type { ChatCompletionsChunk } from "~/services/copilot-vscode/chat-completions/types.streaming"
@@ -13,7 +15,16 @@ chatCompletionsRoutes.post("/chat/completions", async (c) => {
1315
1416 payload . stream = false
1517
16- const response = await chatCompletions ( payload )
18+ const response = await chatCompletions ( payload ) . catch ( ( error : unknown ) => {
19+ if ( error instanceof FetchError ) {
20+ consola . error (
21+ // eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions
22+ `Request failed: ${ JSON . stringify ( payload ) } \n ${ error } \n ${ error . response ?. _data } ` ,
23+ )
24+ }
25+
26+ throw error
27+ } )
1728
1829 const segmenter = new Intl . Segmenter ( "en" , { granularity : "word" } )
1930
Original file line number Diff line number Diff line change 1- import { ofetch } from "ofetch"
1+ import consola from "consola"
2+ import { FetchError , ofetch } from "ofetch"
23
34import { TOKENS } from "~/lib/tokens"
45
@@ -11,6 +12,24 @@ export const copilot = ofetch.create({
1112 onRequest ( { options } ) {
1213 options . headers . set ( "authorization" , `Bearer ${ TOKENS . COPILOT_TOKEN } ` )
1314 } ,
15+
16+ onRequestError ( { error, options } ) {
17+ if ( error instanceof FetchError ) {
18+ consola . error (
19+ // eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions
20+ `Request failed: ${ options . body } \n ${ error } ` ,
21+ )
22+ }
23+ } ,
24+
25+ onResponseError ( { error, response, options } ) {
26+ if ( error instanceof FetchError ) {
27+ consola . error (
28+ // eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions
29+ `Request failed: ${ options . body } \n ${ error } \n with response: ${ JSON . stringify ( response ) } ` ,
30+ )
31+ }
32+ } ,
1433} )
1534
1635export const github = ofetch . create ( {
You can’t perform that action at this time.
0 commit comments