From 2376887a3d6d27d2904641053f10fe6d9d07439f Mon Sep 17 00:00:00 2001 From: Sean Goedecke Date: Thu, 24 Oct 2024 21:55:57 +0000 Subject: [PATCH] Work around nil copilot_references and log 400 errors --- src/functions/execute-model.ts | 7 ++++--- src/index.ts | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/functions/execute-model.ts b/src/functions/execute-model.ts index 3eaa97b..e1afb55 100644 --- a/src/functions/execute-model.ts +++ b/src/functions/execute-model.ts @@ -51,9 +51,10 @@ Example Queries (IMPORTANT: Phrasing doesn't have to match): ): Promise { // Check if the user included any code references in their last message const lastMessage = messages[messages.length - 1]; - const importantRefs = lastMessage.copilot_references.filter( - (ref) => ref.type === "client.selection" || ref.type === "client.file" - ); + let importantRefs: Reference[] = []; + if (lastMessage.copilot_references) { + importantRefs = lastMessage.copilot_references.filter((ref) => ref.type === "client.selection" || ref.type === "client.file"); + } const content = [ `The user has chosen to use the model named ${args.model}.`, diff --git a/src/index.ts b/src/index.ts index 0be573c..a490471 100644 --- a/src/index.ts +++ b/src/index.ts @@ -224,6 +224,11 @@ const server = createServer(async (request, response) => { response.end(); } catch (err) { console.error(err); + + if ((err as any).response && (err as any).response.status === 400) { + console.error('Error 400:', (err as any).response.data); + } + response.statusCode = 500 response.write("data: Something went wrong\n\n") response.end()