Add explicit handling for 429 error code from OpenAI

This commit is contained in:
David Dworken 2024-02-06 20:02:09 -08:00
parent fc4eb6eb6b
commit ae14d5dd7a
No known key found for this signature in database

View File

@ -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 {