error.code always match.
error.details object with extra fields. The clearest example is an insufficient funds error, which tells you the reference, the price, and your balance:
Status codes
Which errors charge you
Only a completed check charges your wallet, and only when it returns an answer. None of the errors above debit you:402,403,422are refused before the provider is called.500and502mean the check failed, which is never charged.
502 and, in the wallet race case, a 402 include a reference in error.details, so a failed attempt is still traceable in support and in your list.
Authentication errors in detail
Handling errors well
1
Branch on status first
Read the top level
status boolean. If false, read error; never assume data is present on a failure.2
Use error.code, not the message text
Branch your logic on the numeric
code. Messages are for humans and may be refined over time; the codes are stable.3
Keep any reference
When
error.details.reference is present, log it. It ties a failed attempt to your support request and to your verification list.4
Do not loop retries
A
402, 403, or 422 will not succeed on retry without a change on your side. A 502 may be transient, but each retry is a fresh, potentially billed check, so retry once at most and reconcile from the list. See References and retrieval.