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:
Naoki Ikeguchi 2022-07-12 14:13:11 +09:00 committed by GitHub
parent d94b350a31
commit b7d3cfd093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View File

@ -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/

View File

@ -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":{