From ae14d5dd7ac29455822012d4ff7ffeeef593c897 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Tue, 6 Feb 2024 20:02:09 -0800 Subject: [PATCH] Add explicit handling for 429 error code from OpenAI --- shared/ai/ai.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shared/ai/ai.go b/shared/ai/ai.go index 53fcdaf..c6093ef 100644 --- a/shared/ai/ai.go +++ b/shared/ai/ai.go @@ -97,6 +97,9 @@ func GetAiSuggestionsViaOpenAiApi(query, shellName, osName string, numberComplet if err != nil { return nil, OpenAiUsage{}, fmt.Errorf("failed to read OpenAI API response: %w", err) } + if resp.StatusCode == 429 { + return nil, OpenAiUsage{}, fmt.Errorf("received 429 error code from OpenAI (is your API key valid?)") + } var apiResp openAiResponse err = json.Unmarshal(bodyText, &apiResp) if err != nil {