From b7d3cfd0937ced9d5c12ef3edc7d6563a20d04ef Mon Sep 17 00:00:00 2001 From: Naoki Ikeguchi Date: Tue, 12 Jul 2022 14:13:11 +0900 Subject: [PATCH] feat: Add missing fields into ErrorResponseDetail (#242) * feat: Add missing fields into ErrorResponseDetail * test: Add the example response as an unit test --- types.go | 8 +++++--- unit_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) 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":{