forked from go-packages/paypal
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
8
types.go
8
types.go
|
@ -495,9 +495,11 @@ type (
|
||||||
|
|
||||||
// ErrorResponseDetail struct
|
// ErrorResponseDetail struct
|
||||||
ErrorResponseDetail struct {
|
ErrorResponseDetail struct {
|
||||||
Field string `json:"field"`
|
Field string `json:"field"`
|
||||||
Issue string `json:"issue"`
|
Issue string `json:"issue"`
|
||||||
Links []Link `json:"link"`
|
Name string `json:"name"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Links []Link `json:"link"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrorResponse https://developer.paypal.com/docs/api/errors/
|
// ErrorResponse https://developer.paypal.com/docs/api/errors/
|
||||||
|
|
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) {
|
func TestTypePayoutResponse(t *testing.T) {
|
||||||
response := `{
|
response := `{
|
||||||
"batch_header":{
|
"batch_header":{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user