Skip to content

Commit

Permalink
Merge pull request #317 from drone/jobatzil/misc/harness_error
Browse files Browse the repository at this point in the history
[Harness] Add support for harness error message
  • Loading branch information
karansaraswat19 authored Jul 29, 2024
2 parents efdcec6 + f23ffd9 commit 4c976e1
Showing 1 changed file with 12 additions and 5 deletions.
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
}

0 comments on commit 4c976e1

Please sign in to comment.