Skip to content

Commit

Permalink
fix: no errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Jun 19, 2024
1 parent a94951e commit e7925b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion err.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type UnexpectedResponse struct {
}

func (r UnexpectedResponse) Error() string {
return fmt.Sprintf("Unexpected response from API. status: %d body: %s", r.Status, r.Body)
return fmt.Sprintf("Unexpected response from API. Status: %d Body: %s", r.Status, r.Body)
}

type ErrResponse struct {
Expand All @@ -21,5 +21,8 @@ type ErrResponse struct {
}

func (e ErrResponse) Error() string {
if len(e.Errors) == 0 {
return fmt.Sprintf("Error during API call. Status: %d Type: %s Title: %s", e.Status, e.Type, e.Title)
}
return fmt.Sprintf("Error during API call. Status: %d Type: %s Title: %s Errors: %s", e.Status, e.Type, e.Title, e.Errors)
}
6 changes: 3 additions & 3 deletions err_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ var badRequestValidationNoErrors []byte

func TestUnexpectedResponse(t *testing.T) {
resp := clearbank.UnexpectedResponse{Status: 500, Body: "I am an error."}
assert.Equal(t, resp.Error(), "Unexpected response from API. status: 500 body: I am an error.")
assert.Equal(t, "Unexpected response from API. Status: 500 Body: I am an error.", resp.Error())
}

func TestErrResponse(t *testing.T) {
resp := clearbank.ErrResponse{Status: 500, Type: "abcd", Title: "I am an error."}
assert.Equal(t, resp.Error(), "Error during API call. status: 500 type: abcd title: I am an error.")
assert.Equal(t, "Error during API call. Status: 500 Type: abcd Title: I am an error.", resp.Error())
}

func TestErrResponse_Errors(t *testing.T) {
Expand All @@ -42,5 +42,5 @@ func TestErrResponse_NoErrors(t *testing.T) {
assert.NoError(t, err)

assert.Len(t, resp.Errors, 0)
assert.Equal(t, "Error during API call. Status: 400 Type: https://tools.ietf.org/html/rfc7231#section-6.5.1 Title: One or more validation errors occurred. Errors: map[]", resp.Error())
assert.Equal(t, "Error during API call. Status: 400 Type: https://tools.ietf.org/html/rfc7231#section-6.5.1 Title: One or more validation errors occurred.", resp.Error())
}

0 comments on commit e7925b3

Please sign in to comment.