From 96133488953899cb74f875050b4f066ca33ff832 Mon Sep 17 00:00:00 2001 From: Travis Bischel Date: Thu, 10 Oct 2024 20:53:04 -0600 Subject: [PATCH] sr: add StatusCode to ResponseError, and message if the body is empty Closes #819. --- pkg/sr/client.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/sr/client.go b/pkg/sr/client.go index c2e9b2ce..f2f33a1a 100644 --- a/pkg/sr/client.go +++ b/pkg/sr/client.go @@ -34,6 +34,8 @@ type ResponseError struct { Method string `json:"-"` // URL is the full path that was requested that resulted in this error. URL string `json:"-"` + // StatusCode is the status code that was returned for this error. + StatusCode int `json:"-"` // Raw contains the raw response body. Raw []byte `json:"-"` @@ -149,9 +151,13 @@ start: if resp.StatusCode >= 300 { e := &ResponseError{ - Method: method, - URL: reqURL, - Raw: body, + Method: method, + URL: reqURL, + StatusCode: resp.StatusCode, + Raw: bytes.TrimSpace(body), + } + if len(e.Raw) == 0 { + e.Message = "no response" } _ = json.Unmarshal(body, e) // best effort return e