Skip to content

Commit

Permalink
Extend error response (#63)
Browse files Browse the repository at this point in the history
* Update error handling with more data

* Remove a debug line from live test suite
  • Loading branch information
trevrosen authored Apr 5, 2019
1 parent 28d89d1 commit 58702c0
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 38 deletions.
145 changes: 113 additions & 32 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions _live-tests/charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package live_tests
import (
"testing"

"fmt"

"time"

"github.com/appoptics/appoptics-api-go"
Expand Down Expand Up @@ -55,7 +53,6 @@ func TestCharts(t *testing.T) {
})

t.Run("Update", func(t *testing.T) {
fmt.Printf("UPDATE CHART: %+v\n", chart)
otherName := "new-name"
chart.Name = otherName
updatedChart, err := client.ChartsService().Update(chart, spaceID)
Expand Down
7 changes: 4 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ type ServiceAccessor interface {
// ErrorResponse represents the response body returned when the API reports an error
type ErrorResponse struct {
// Errors holds the error information from the API
Errors interface{} `json:"errors"`
Errors interface{} `json:"errors"`
Response *http.Response
}

// QueryInfo holds pagination information coming from list actions
Expand Down Expand Up @@ -315,6 +316,7 @@ func clientVersionString() string {
func checkError(resp *http.Response) error {
errResponse := &ErrorResponse{}
if resp.StatusCode >= 400 {
errResponse.Response = resp
if resp.ContentLength != 0 {
decoder := json.NewDecoder(resp.Body)
err := decoder.Decode(errResponse)
Expand All @@ -325,8 +327,7 @@ func checkError(resp *http.Response) error {
log.Debugf("error: %+v\n", errResponse)
return errResponse
}
msg := fmt.Sprintf("unknown error with status %d", resp.StatusCode)
return errors.New(msg)
return errResponse
}
return nil
}
Expand Down

0 comments on commit 58702c0

Please sign in to comment.