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 /api/mint-wax endpoint 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.
Wax key expiry is handled automatically. When a wax key expires or is consumed between initialization and the user clicking Pay, the SDK silently re-mints a fresh key and retries once. You will only receive an auth error if the re-mint itself fails (e.g. your backend mint endpoint is down or returns an error). The proactive refresh — triggered once maxTokenizeCalls successful tokenizations 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.
In React, OzVault.create() is called inside the <OzElements> provider. If it fails (e.g. fetchWaxKey threw or returned an empty string), 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 PayAPI 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 PayAPI cardSale error strings to user-facing messages. Use this when your backend processes a charge via the Pay 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."