Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,9 @@ type (
// ErrorResponseDetail struct
ErrorResponseDetail struct {
Field string `json:"field"`
Value string `json:"value"`
Location string `json:"location"`
Issue string `json:"issue"`
Name string `json:"name"`
Message string `json:"message"`
Description string `json:"description"`
Links []Link `json:"link"`
}
Expand All @@ -743,6 +743,7 @@ type (
Message string `json:"message"`
InformationLink string `json:"information_link"`
Details []ErrorResponseDetail `json:"details"`
Links []Link `json:"link"`
}

// ExecuteAgreementResponse struct
Expand Down
35 changes: 21 additions & 14 deletions unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,37 @@ 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"
}
]
}`
"name": "DUPLICATE_TRACKER",
"message": "Business error",
"debug_id": "[REDACTED]",
"details": [
{
"field": "#/trackers/0/tracking_number",
"value": "[TRACKING_NUMBER]",
"location": "body",
"issue": "TRACKING_NUMBER_ALREADY_EXIST",
"description": "Tracking information already exists with same Tracking number",
"links": [

]
}
]
}`

i := &ErrorResponse{}
err := json.Unmarshal([]byte(response), i)
if err != nil {
t.Errorf("ErrorResponse Unmarshal failed")
}

if i.Name != "BUSINESS_ERROR" ||
if i.Name != "DUPLICATE_TRACKER" ||
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" {
i.Details[0].Issue != "TRACKING_NUMBER_ALREADY_EXIST" ||
i.Details[0].Value != "[TRACKING_NUMBER]" ||
i.Details[0].Description != "Tracking information already exists with same Tracking number" {
t.Errorf("ErrorResponse decoded result is incorrect, Given: %v", i)
}
}
Expand Down