6Error Handling
Proper error handling is critical for a robust payment integration. Here are common errors and how to handle them:
| Error Type | Possible Causes | Handling Strategy |
|---|---|---|
| Authentication Error |
|
|
| Validation Error |
|
|
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 Status | Error Code | Description |
|---|---|---|
| 400 | INVALID_REQUEST | Bad payload. |
| 401 | UNAUTHORIZED | Token missing, invalid, or expired. |
| 422 | VALIDATION_ERROR | Input failed validation. |
| 500 | SERVER_ERROR | Unexpected system failure. |