diff --git a/types.go b/types.go index 3e950bd..8fda20a 100644 --- a/types.go +++ b/types.go @@ -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/ diff --git a/unit_test.go b/unit_test.go index 589dfcf..bb3d8fd 100644 --- a/unit_test.go +++ b/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":{