6
Error Handling

Proper error handling is critical for a robust payment integration. Here are common errors and how to handle them:

Error TypePossible CausesHandling Strategy
Authentication Error
  • Invalid client credentials
  • Expired access token
  • Request a new token and retry once.
  • Return a clear message for operators in logs.
Validation Error
  • Missing required fields
  • Malformed payload values
  • Display field-level validation errors.
  • Prevent duplicate retries until payload is corrected.

Implementing Robust Error Handling

Typed API error handler
try {
  await createCheckoutSession(payload);
} catch (err: any) {
  if (err?.status === 401) {
    await refreshAccessToken();
  } else if (err?.status === 422) {
    showValidationErrors(err.data?.fields ?? {});
  } else {
    reportError(err);
  }
}

Do not leak internals: Return generic user-facing errors and keep stack traces confined to server logs.

Common Error Codes

The SaligPay API uses standard HTTP status codes along with custom error codes in the response body.

HTTP StatusError CodeDescription
400INVALID_REQUESTBad payload.
401UNAUTHORIZEDToken missing, invalid, or expired.
422VALIDATION_ERRORInput failed validation.
500SERVER_ERRORUnexpected system failure.