mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 02:11:02 +01:00
feat: Add missing fields into ErrorResponseDetail (#242)
* feat: Add missing fields into ErrorResponseDetail * test: Add the example response as an unit test
This commit is contained in:
parent
d94b350a31
commit
b7d3cfd093
2
types.go
2
types.go
|
@ -497,6 +497,8 @@ type (
|
|||
ErrorResponseDetail struct {
|
||||
Field string `json:"field"`
|
||||
Issue string `json:"issue"`
|
||||
Name string `json:"name"`
|
||||
Message string `json:"message"`
|
||||
Links []Link `json:"link"`
|
||||
}
|
||||
|
||||
|
|
29
unit_test.go
29
unit_test.go
|
@ -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":{
|
||||
|
|
Loading…
Reference in New Issue
Block a user