Skip to content

Commit

Permalink
feat: Add missing fields into ErrorResponseDetail (#242)
Browse files Browse the repository at this point in the history
* feat: Add missing fields into ErrorResponseDetail

* test: Add the example response as an unit test
  • Loading branch information
siketyan authored Jul 12, 2022
1 parent d94b350 commit b7d3cfd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 5 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ type (

// ErrorResponseDetail struct
ErrorResponseDetail struct {
Field string `json:"field"`
Issue string `json:"issue"`
Links []Link `json:"link"`
Field string `json:"field"`
Issue string `json:"issue"`
Name string `json:"name"`
Message string `json:"message"`
Links []Link `json:"link"`
}

// ErrorResponse https://developer.paypal.com/docs/api/errors/
Expand Down
29 changes: 29 additions & 0 deletions unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,35 @@ func TestTypeErrorResponseTwo(t *testing.T) {
}
}

func TestTypeErrorResponseThree(t *testing.T) {
response := `{
"name": "BUSINESS_ERROR",
"debug_id": "[REDACTED]",
"message": "Business error",
"information_link": "https://developer.paypal.com/webapps/developer/docs/api/#BUSINESS_ERROR",
"details": [
{
"name": "TOKEN_NOT_FOUND",
"message": "Not Found: Invalid BA-Token Identifier"
}
]
}`

i := &ErrorResponse{}
err := json.Unmarshal([]byte(response), i)
if err != nil {
t.Errorf("ErrorResponse Unmarshal failed")
}

if i.Name != "BUSINESS_ERROR" ||
i.Message != "Business error" ||
len(i.Details) != 1 ||
i.Details[0].Name != "TOKEN_NOT_FOUND" ||
i.Details[0].Message != "Not Found: Invalid BA-Token Identifier" {
t.Errorf("ErrorResponse decoded result is incorrect, Given: %v", i)
}
}

func TestTypePayoutResponse(t *testing.T) {
response := `{
"batch_header":{
Expand Down

0 comments on commit b7d3cfd

Please sign in to comment.