diff --git a/error.go b/error.go index 9370205..1c06f09 100644 --- a/error.go +++ b/error.go @@ -1,6 +1,7 @@ package lago import ( + "encoding/json" "errors" "net/http" ) @@ -28,6 +29,19 @@ type Error struct { ErrorDetail map[string][]string `json:"error_details,omitempty"` } +func (e Error) Error() string { + type alias struct { + Error + Err string `json:"err,omitempty"` + } + err := alias{Error: e} + if e.Err != nil { + err.Err = e.Err.Error() + } + msg, _ := json.Marshal(&err) + return string(msg) +} + func (e ErrorCode) Error() string { return string(e) } diff --git a/error_test.go b/error_test.go new file mode 100644 index 0000000..c9ec21e --- /dev/null +++ b/error_test.go @@ -0,0 +1,23 @@ +package lago + +import ( + "errors" + "testing" +) + +func TestErrorErr(t *testing.T) { + var hasErr error = Error{ + Err: errors.New("type assertion failed"), + HTTPStatusCode: 422, + Message: "Type assertion failed", + } + t.Logf("%s", hasErr.Error()) +} + +func TestErrorNoErr(t *testing.T) { + var noErr error = Error{ + HTTPStatusCode: 500, + Message: "500", + } + t.Logf("%s", noErr.Error()) +} diff --git a/invoice.go b/invoice.go index a7607e5..23e77af 100644 --- a/invoice.go +++ b/invoice.go @@ -149,6 +149,7 @@ type Invoice struct { IssuingDate string `json:"issuing_date,omitempty"` PaymentDisputeLostAt time.Time `json:"payment_dispute_lost_at,omitempty"` PaymentDueDate string `json:"payment_due_date,omitempty"` + PaymentOverdue bool `json:"payment_overdue,omitempty"` InvoiceType InvoiceType `json:"invoice_type,omitempty"` Status InvoiceStatus `json:"status,omitempty"`