This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
50 lines (43 loc) · 1.79 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package stripe
import "encoding/json"
// ErrorType is the list of allowed values for the error's type.
// Allowed values are "invalid_request_error", "api_error", "card_error".
type ErrorType string
// ErrorCode is the list of allowed values for the error's code.
// Allowed values are "incorrect_number", "invalid_number", "invalid_expiry_month",
// "invalid_expiry_year", "invalid_cvc", "expired_card", "incorrect_cvc", "incorrect_zip",
// "card_declined", "missing", "processing_error", "rate_limit".
type ErrorCode string
const (
InvalidRequest ErrorType = "invalid_request_error"
APIErr ErrorType = "api_error"
CardErr ErrorType = "card_error"
IncorrectNum ErrorCode = "incorrect_number"
InvalidNum ErrorCode = "invalid_number"
InvalidExpM ErrorCode = "invalid_expiry_month"
InvalidExpY ErrorCode = "invalid_expiry_year"
InvalidCvc ErrorCode = "invalid_cvc"
ExpiredCard ErrorCode = "expired_card"
IncorrectCvc ErrorCode = "incorrect_cvc"
IncorrectZip ErrorCode = "incorrect_zip"
CardDeclined ErrorCode = "card_declined"
Missing ErrorCode = "missing"
ProcessingErr ErrorCode = "processing_error"
RateLimit ErrorCode = "rate_limit"
)
// Error is the response returned when a call is unsuccessful.
// For more details see https://stripe.com/docs/api#errors.
type Error struct {
Type ErrorType `json:"type"`
Msg string `json:"message"`
Code ErrorCode `json:"code,omitempty"`
Param string `json:"param,omitempty"`
RequestID string `json:"request_id,omitempty"`
HTTPStatusCode int `json:"status,omitempty"`
ChargeID string `json:"charge,omitempty"`
}
// Error serializes the Error object and prints the JSON string.
func (e *Error) Error() string {
ret, _ := json.Marshal(e)
return string(ret)
}