Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Error Handling

This page covers error handling for both API endpoints and SDK integration.


API Error Handling

When calling Payr API endpoints (Onboarding, Authentication, Payment Session), you may receive the following HTTP status codes and error responses.

Common HTTP Status Codes

Status
Meaning
What to Check

400

Bad Request

Validation errors in request body — check required fields and data formats

401

Unauthorized

API token is invalid, expired, or missing

403

Forbidden

Insufficient permissions or resource access denied

404

Not Found

Resource does not exist or session has expired

Error Response Formats

Authentication errors:

{ "detail": "Invalid token." }
{ "detail": "Authentication credentials were not provided." }

Validation errors (field-level):

{
  "email": ["This field is required."],
  "user_id": ["This field is required."],
  "tenant": ["This field is required."]
}

Nested validation errors (within tenant/installment arrays):

Processing errors:


SDK Error Handling

When using the Payr JavaScript SDK, errors are returned through the onError callback function configured in PAYR.init().

SDK Error Codes

Code
Description

INIT_FAILED

SDK initialization failed (e.g., invalid config, container not found)

VALIDATION_ERROR

Invalid payment request or missing required data (e.g., amount, currency)

WORLDPAY_ERROR

Card processing error from WorldPay (e.g., invalid CVC, card declined)

NETWORK_ERROR

Network failure during API calls to Payr backend

PAYMENT_FAILED

Payment declined or failed by the payment gateway

USER_CANCELLED

User closed a 3DS, APM, or wallet verification overlay

Example: SDK Error Handling

Error Object Structure

SDK errors are returned as objects with the following properties:

Best Practices

  1. Always implement onError - Don't rely on default browser error handling

  2. Show user-friendly messages - Don't expose technical error details to end users

  3. Log errors for debugging - Use console.error() or your logging service

  4. Handle USER_CANCELLED gracefully - This isn't necessarily an error; the user may simply need to retry

  5. Provide retry options - Allow users to attempt payment again after errors

  6. Test error scenarios - Use sandbox environment to test different error conditions


When to Use Each Error Handling Approach

  • API Error Handling - Use when calling backend API endpoints directly from your server

  • SDK Error Handling - Use when implementing the JavaScript SDK in your frontend

Both approaches work together: your backend handles API errors when creating sessions or onboarding users, while your frontend handles SDK errors during the payment process.

Last updated