PaperTiger.Error exception (PaperTiger v0.9.20)
View SourceStripe-compatible error responses.
Matches Stripe's error structure and HTTP status codes.
Error Types
invalid_request_error- Bad request (400)api_error- Server error (500)card_error- Card declined (402)rate_limit_error- Too many requests (429)
Examples
# Not found error
PaperTiger.Error.not_found("customer", "cus_123")
# => %PaperTiger.Error{
# type: "invalid_request_error",
# message: "No such customer: 'cus_123'",
# status: 404
# }
# Card declined
PaperTiger.Error.card_declined()
# => %PaperTiger.Error{
# type: "card_error",
# code: "card_declined",
# message: "Your card was declined.",
# status: 402
# }
Summary
Functions
Creates an API error (500).
Creates a card declined error (402).
Creates an invalid request error (400).
Creates a not found error (404).
Creates a rate limit error (429).
Converts error to Stripe's JSON format.
Types
Functions
Creates an API error (500).
Creates a card declined error (402).
Options
:code- Decline code (default: "card_declined")
Possible codes:
card_declined- Generic declineinsufficient_funds- Not enough moneyexpired_card- Card expiredincorrect_cvc- CVC check failed
Creates an invalid request error (400).
If a param is provided, it will be appended to the message in the format: "message: param"
Examples
PaperTiger.Error.invalid_request("Missing required parameter", :customer)
# => %PaperTiger.Error{
# message: "Missing required parameter: customer",
# param: "customer",
# status: 400,
# type: "invalid_request_error"
# }
Creates a not found error (404).
Returns the same error format as Stripe's API for missing resources.
Param Values by Resource Type
Stripe uses different param values depending on the resource:
customer,product,subscription->"id"price->"price"plan->"plan"invoice->"invoice"payment_intent->"intent"
Examples
PaperTiger.Error.not_found("customer", "cus_123")
# => %PaperTiger.Error{
# code: "resource_missing",
# message: "No such customer: 'cus_123'",
# param: "id",
# status: 404,
# type: "invalid_request_error"
# }
@spec rate_limit() :: t()
Creates a rate limit error (429).
Converts error to Stripe's JSON format.
Examples
PaperTiger.Error.not_found("customer", "cus_123")
|> PaperTiger.Error.to_json()
# => %{
# error: %{
# type: "invalid_request_error",
# message: "No such customer: 'cus_123'"
# }
# }