From e1d457c73ee80fe9bb4044d5b7106bc6bf4301c7 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Sun, 31 Mar 2024 09:34:58 -0700 Subject: [PATCH] client/ollama: report invalid server error response with raw bytes --- client/ollama/ollama.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/ollama/ollama.go b/client/ollama/ollama.go index 06ee7fa2..1101b5b9 100644 --- a/client/ollama/ollama.go +++ b/client/ollama/ollama.go @@ -5,6 +5,7 @@ import ( "cmp" "context" "encoding/json" + "fmt" "io" "io/fs" "iter" @@ -109,8 +110,11 @@ func Do[Res any](ctx context.Context, method, urlStr string, in any) (*Res, erro defer res.Body.Close() if res.StatusCode/100 != 2 { - e, err := decodeJSON[Error](res.Body) + var buf bytes.Buffer + body := io.TeeReader(res.Body, &buf) + e, err := decodeJSON[Error](body) if err != nil { + err := fmt.Errorf("ollama: invalid error response from server (status %d): %q", res.StatusCode, buf.String()) return nil, err } return nil, e