From 75d77001b1076d3c20cf3305d58e13e5bc763362 Mon Sep 17 00:00:00 2001 From: hiroki osame Date: Wed, 22 Feb 2023 00:16:01 -0500 Subject: [PATCH] fix: handle unreachable openai.com (#100) --- src/utils/openai.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/openai.ts b/src/utils/openai.ts index 730ac397..918d9951 100644 --- a/src/utils/openai.ts +++ b/src/utils/openai.ts @@ -38,6 +38,10 @@ export const generateCommitMessage = async ( ); } catch (error) { const errorAsAny = error as any; + if (errorAsAny.code === 'ENOTFOUND') { + throw new Error(`Error connecting to ${errorAsAny.hostname} (${errorAsAny.syscall}). Are you connected to the internet?`); + } + errorAsAny.message = `OpenAI API Error: ${errorAsAny.message} - ${errorAsAny.response.statusText}`; throw errorAsAny; }