diff --git a/scm/driver/harness/harness.go b/scm/driver/harness/harness.go index 1feb6a46..cf71dd7f 100644 --- a/scm/driver/harness/harness.go +++ b/scm/driver/harness/harness.go @@ -8,9 +8,7 @@ import ( "bytes" "context" "encoding/json" - "errors" "io" - "net/http" "net/url" "strings" @@ -82,9 +80,9 @@ func (c *wrapper) do(ctx context.Context, method, path string, in, out interface // if an error is encountered, unmarshal and return the // error response. if res.Status > 300 { - return res, errors.New( - http.StatusText(res.Status), - ) + err := new(Error) + json.NewDecoder(res.Body).Decode(err) + return res, err } if out == nil { @@ -102,3 +100,12 @@ func (c *wrapper) do(ctx context.Context, method, path string, in, out interface // the json response. return res, json.NewDecoder(res.Body).Decode(out) } + +// Error represents a Harness CODE error. +type Error struct { + Message string `json:"message"` +} + +func (e *Error) Error() string { + return e.Message +}