Errors and retries
Every failed call throws a class of the MountayaException family. The client retries what is worth retrying before it gives up.
ApiException catches every failure the API answered, with its status, code, errors and requestId. A timeout or a dropped connection is a ConnectionException instead, and carries none of them.
A 402 is fixed in your agreement or billing settings, not in code. Its message says which.
code is an ApiErrorCode, the same type for every API. hasCode asks whether any entry carries a code:
Retries are on by default: two retries with backoff, on 429, 502, 503, 504 and dropped connections. Writes are retried safely, because each one carries an idempotency key.
The client's timeout is 30 seconds. Give one call a shorter one, and withdraw the whole call, retries included, with an AbortSignal:
onResponse hears every attempt an answer came back to, successes included: