Error handling
Distinguish configuration mistakes (
GoPayConfigError) from API responses (GoPayApiError). They need different logging, alerting, and retry behavior.Error classes
GoPayApiError
Thrown for non-2xx HTTP responses from GoPay endpoints.
Useful fields:
status: HTTP status codeendpoint: full endpoint URL or endpoint patherrors: parsed GoPay field errors when presentrawResponse: parsed JSON payload or raw text payload
GoPayConfigError
Thrown when client configuration is invalid (for example invalid gatewayUrl or missing credentials).
Recommended pattern
Suggested retry policy
- Retry only safe/idempotent operations by default (for example
getPayment) - Use bounded retries with exponential backoff
- Add jitter to avoid synchronized retries
- Do not blindly retry validation failures (
4xxwith clear field errors)
Logging best practices
- Log
endpoint,status, and sanitized error metadata (not raw bodies with PII). - Include a correlation or request ID on every log line for support and tracing.