Errors
Cyan uses standard HTTP status codes. A 2xx means the request worked. Anything else comes with a JSON body that says what went wrong:
{ "error": { "code": "validation_error", "message": "Check the request's fields and try again.", "params": [ { "name": "amount", "message": "Must be at least 1" }, { "name": "embed", "message": "Not a field this request takes" } ] }}codesays which error it is. It never changes, so branch on it in your code.messageexplains it for you, not for your customer. Its wording can change.paramscomes with avalidation_erroronly, and names each field to fix.
Error codes
Section titled “Error codes”| Status | code |
What to do |
|---|---|---|
400 |
validation_error |
Fix the fields named in params. |
400 |
idempotency_key_required |
Send an Idempotency-Key header when you create a link. |
400 |
amount_below_minimum |
Raise the amount. Your Stripe account has a minimum per payment, such as $0.50. |
400 |
amount_above_maximum |
Lower the amount. |
400 |
currency_not_supported |
Use a currency your Stripe account can charge in. |
401 |
api_key_missing |
Send your key in the Authorization header. |
401 |
invalid_api_key |
Check your key. If you regenerated it, use the new one. |
403 |
provider_not_connected |
Connect your Stripe account in the app under Settings → Connectors. |
403 |
provider_disconnected |
The link’s Stripe account no longer lets Cyan in. Reconnect it in the app. |
404 |
payment_link_not_found |
Check the ID. A link is only found with the key of the business that created it. |
404 |
route_not_found |
Check the path. |
405 |
method_not_allowed |
Use a method the Allow header lists. |
409 |
idempotency_key_in_use |
A request with the same key is still running. Send yours again in a moment. |
409 |
payment_link_not_cancelable |
The link is processing or paid. Refund it in your Stripe Dashboard instead. |
415 |
unsupported_media_type |
Send the body as JSON, with Content-Type: application/json. |
422 |
idempotency_key_mismatch |
You sent this key before with a different body. Use a new key for a new payment. |
500 |
internal_error |
Try again. |
502 |
provider_unavailable |
Stripe couldn’t handle the request just now. Try again. |
Handling errors in code
Section titled “Handling errors in code”const response = await fetch("https://api.cyan.cash/v1/payment-links", options);const body = await response.json();
if (!response.ok) { console.error(`Cyan ${response.status} ${body.error.code}: ${body.error.message}`); throw new Error("We couldn't start the payment. Please try again.");}Retries
Section titled “Retries”Creating a link takes an Idempotency-Key, so retrying a create is always safe:
- The same key and body returns the link the first request made, with
201. Nothing is created twice, however many times you retry. - The same key with a different body returns
422 idempotency_key_mismatch. - Two requests with the same key at once: the second may get
409 idempotency_key_in_use. Retry it.
Use a key that belongs to the payment, such as your order’s ID. Keys belong to your business, so they never clash with another business’s.
What else to retry:
409 idempotency_key_in_use,500and502: yes. Wait a moment and send the same request again.- A timeout: yes, with the same
Idempotency-Keywhen it was a create. - Any other
4xx: no. The same request will fail the same way, so fix the cause first.