Error Handling
createToken() and createBankToken() both throw an OzError when tokenization fails. Wrap calls in a try/catch and inspect .errorCode to decide how to respond.
OzError
OzError properties
| Property | Type | Description |
|---|---|---|
message | string | Normalized, user-friendly error message |
errorCode | OzErrorCode | Machine-readable code (see table below) |
raw | string | Raw message returned by the Vault API (use for logging, not display) |
retryable | boolean | true for transient errors (network, timeout, server). false for permanent failures where retrying with the same input won’t help. |
Error Codes
errorCode | retryable | Meaning | What to do |
|---|---|---|---|
'network' | ✅ | Request failed due to a network error (offline, DNS failure, etc.) | Show a “check your connection” message. Retry is safe. |
'timeout' | ✅ | Tokenization took longer than 30 seconds | Show a timeout message. Retry is safe. |
'server' | ✅ | Vault returned a 5xx error | Retry after a short delay. Log for investigation. |
'auth' | ❌ | Invalid or missing API key / pub key | Check your credentials. Do not retry without fixing config. |
'validation' | ❌ | Request was malformed or the vault rejected input | Check request parameters. Usually a developer error. |
'config' | ❌ | SDK misconfiguration (e.g. disallowed vault origin) | Check your apiUrl configuration. |
'unknown' | ❌ | Unclassified error | Log and surface a generic message. |
Recommended Pattern
SDK-Level Errors (Thrown Before Tokenization)
Some errors are thrown by the SDK before any network request is made. These are alsoOzError instances:
| Condition | Message |
|---|---|
| Vault not yet ready | "Vault not ready. Ensure the page is fully loaded before calling createToken." |
| Tokenization already in progress | "A tokenization is already in progress. Wait for it to complete before calling createToken() again." |
| No elements mounted | "No elements are mounted and ready. Mount at least one element before calling createToken." |
| Vault destroyed | "Cannot tokenize on a destroyed vault. Create a new OzVault instance." |
Missing firstName (bank) | "firstName is required for bank account tokenization." |
Missing lastName (bank) | "lastName is required for bank account tokenization." |
Load Errors
If the tokenizer iframe fails to load (network issue, blocked by CSP, etc.), useonLoadError:
loaderror event:
normalizeCardSaleError
If you’re using PayAPI to process a charge and need to map raw error strings to user-friendly messages,normalizeCardSaleError handles this: