Handle OzError instances from createToken() and createBankToken(), understand error codes, and surface errors to users.
createToken() and createBankToken() both throw an OzError when tokenization fails. Wrap calls in a try/catch and inspect .errorCode to decide how to respond.
If you see this in production after a successful initial load, the auto-refresh failed — check that your session endpoint (/api/oz-session) is reachable. Otherwise verify credentials.
'validation'
❌
Request was malformed or the vault rejected input
Check request parameters. Usually a developer error.
'config'
❌
Unexpected SDK or environment issue
Log the error and contact Ozura support.
'unknown'
❌
Unclassified error
Log and surface a generic message.
Session key expiry is handled automatically. When a session key expires or is consumed between initialization and the user clicking Pay, the SDK silently fetches a fresh key and retries once. You will only receive an auth error if the refresh itself fails (e.g. your session endpoint is down or returns an error). The proactive refresh — triggered once sessionLimit successful submissions are reached — also prevents expiry from surfacing under normal usage.
These OzError instances are thrown before any network request is made. They represent setup or usage mistakes caught during integration — fix them in code, don’t surface them to the user.
These come from OzVault.create(). If you’re using the React provider, they appear in initError.
Condition
How to fix
pubKey missing
If using a production vault API key, pass a valid pubKey to OzVault.create() / <OzElements>. If using a test/sandbox vault API key, pubKey is not required and can be omitted.
No session option provided
Pass sessionUrl, getSessionKey, or (deprecated) fetchWaxKey to OzVault.create() / <OzElements>.
sessionUrl or getSessionKey returned an empty string
Check your /api/oz-session endpoint — it must return a non-empty sessionKey.
In React, OzVault.create() is called inside the <OzElements> provider. If it fails (e.g. your session endpoint is unreachable or returns an error), useOzElements().initError will be non-null:
The SDK exports three standalone functions that map raw API error strings to user-friendly messages.
OzError.message from createToken() and createBankToken() is already normalized — the SDK calls these functions internally. You only need to call them yourself when you receive raw error strings from a different source (e.g. your backend forwarding a vault or OzuraPay API response).
Maps raw vault /tokenize error strings to user-facing messages for card flows.
import { normalizeVaultError } from '@ozura/elements';const message = normalizeVaultError(rawVaultErrorString);// e.g. "Invalid card number" → "The card number is invalid. Please check and try again."
Maps raw vault /tokenize error strings to user-facing messages for bank/ACH flows.
import { normalizeBankVaultError } from '@ozura/elements';const message = normalizeBankVaultError(rawVaultErrorString);// e.g. "Invalid routing number" → "The routing number is invalid. Please check and try again."
Maps raw OzuraPay API cardSale error strings to user-facing messages. Use this when your backend processes a charge via the OzuraPay API and needs to display the error to the user.
import { normalizeCardSaleError } from '@ozura/elements';const message = normalizeCardSaleError(rawPayApiErrorString);// e.g. "Insufficient Funds" → "Your card has insufficient funds. Please use a different payment method."
All three functions fall back gracefully when no pattern matches:
normalizeVaultError and normalizeBankVaultError — return the original raw string unchanged when no pattern matches.
normalizeCardSaleError — short unrecognized strings (under 100 characters) are returned as-is; long opaque server strings (100+ characters) are replaced with "Payment processing failed. Please try again or contact support." An empty input returns "Payment processing failed. Please try again."