feat(client): show response body on json parsing error
arcad/emissary/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
wpetit 2024-03-04 18:51:36 +01:00
parent 4a1a434556
commit f6ffb68c43
1 changed files with 7 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"net/http" "net/http"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -95,12 +96,15 @@ func (c *Client) apiDo(ctx context.Context, method string, path string, payload
defer res.Body.Close() defer res.Body.Close()
decoder := json.NewDecoder(res.Body) data, err := io.ReadAll(res.Body)
if err != nil {
if err := decoder.Decode(&response); err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
if err := json.Unmarshal(data, &response); err != nil {
return errors.Wrapf(err, "could not parse json: got '%s'", data)
}
return nil return nil
} }