Skip to content

Commit b7d3cfd

Browse files
authored
feat: Add missing fields into ErrorResponseDetail (#242)
* feat: Add missing fields into ErrorResponseDetail * test: Add the example response as an unit test
1 parent d94b350 commit b7d3cfd

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

types.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ type (
495495

496496
// ErrorResponseDetail struct
497497
ErrorResponseDetail struct {
498-
Field string `json:"field"`
499-
Issue string `json:"issue"`
500-
Links []Link `json:"link"`
498+
Field string `json:"field"`
499+
Issue string `json:"issue"`
500+
Name string `json:"name"`
501+
Message string `json:"message"`
502+
Links []Link `json:"link"`
501503
}
502504

503505
// ErrorResponse https://developer.paypal.com/docs/api/errors/

unit_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,35 @@ func TestTypeErrorResponseTwo(t *testing.T) {
144144
}
145145
}
146146

147+
func TestTypeErrorResponseThree(t *testing.T) {
148+
response := `{
149+
"name": "BUSINESS_ERROR",
150+
"debug_id": "[REDACTED]",
151+
"message": "Business error",
152+
"information_link": "https://developer.paypal.com/webapps/developer/docs/api/#BUSINESS_ERROR",
153+
"details": [
154+
{
155+
"name": "TOKEN_NOT_FOUND",
156+
"message": "Not Found: Invalid BA-Token Identifier"
157+
}
158+
]
159+
}`
160+
161+
i := &ErrorResponse{}
162+
err := json.Unmarshal([]byte(response), i)
163+
if err != nil {
164+
t.Errorf("ErrorResponse Unmarshal failed")
165+
}
166+
167+
if i.Name != "BUSINESS_ERROR" ||
168+
i.Message != "Business error" ||
169+
len(i.Details) != 1 ||
170+
i.Details[0].Name != "TOKEN_NOT_FOUND" ||
171+
i.Details[0].Message != "Not Found: Invalid BA-Token Identifier" {
172+
t.Errorf("ErrorResponse decoded result is incorrect, Given: %v", i)
173+
}
174+
}
175+
147176
func TestTypePayoutResponse(t *testing.T) {
148177
response := `{
149178
"batch_header":{

0 commit comments

Comments
 (0)