Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Harness] Add support for harness error message #317

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions scm/driver/harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"net/http"
"net/url"
"strings"

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}