x

Programs, configuration and documentation that don't fit anywhere else
Log | Files | Refs | README | LICENSE

commit a7c097f8bdb5834050510877297d9cfe4a36489f
parent 49653f71d00f24d3302264088121382ef7db1fc2
Author: Oliver Lowe <o@olowe.co>
Date:   Wed,  2 Jul 2025 12:44:03 +1000

openai: reliably return unauthorised errors

Diffstat:
Msrc/openai/openai.go | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/openai/openai.go b/src/openai/openai.go @@ -97,7 +97,9 @@ func (c *Client) Complete(chat *Chat) (*Message, error) { return nil, err } defer resp.Body.Close() - if resp.StatusCode >= 400 && resp.StatusCode <= 499 { + if resp.StatusCode == http.StatusUnauthorized { + return nil, fmt.Errorf("unauthorised") + } else if resp.StatusCode >= 400 && resp.StatusCode <= 499 { var aerr apiError if err := json.NewDecoder(resp.Body).Decode(&aerr); err != nil { return nil, fmt.Errorf(resp.Status)