Catch an error
Every failed request throws a subclass ofPolymorfaError:
Error codes never change meaning. The API can add new ones, so handle unknown
codes.
isKnownPolymorfaErrorCode(code) tells you whether the installed SDK
knows a code.
Error classes
402: the team cannot pay
Paid actions, such as starting a paid Number, reserve credit first. A402
means the team cannot pay for the request or lacks the entitlement. Retrying
does not help. Check the balance and plan in the Console, then try again. The
SDK never retries a 402.
409: the resource changed
Settings with a revision, such as call settings and Number configuration, fail withstate_conflict when someone else changed them after you read them. Read
the current value, apply your change again, and send the new revision.
A 409 with an idempotency_* code concerns your idempotency key. See
Retry a write safely.
429: rate limited
rateLimitReason says which limit applied, such as request_rate or
whatsapp. Wait for the retry-after header before you send again. The SDK
already does this for requests it retries. See Rate limits.
Automatic retries
The SDK retries a request when both are true:- The request is a
GET,HEAD, orOPTIONS, or it has anidempotencyKey. - It failed with a network error, a timeout, or status
408,409,429, or5xx.
Retry-After when the API sends it, up to 60 seconds. Otherwise it
backs off exponentially, up to 5 seconds between attempts. It retries twice by
default. Set maxNetworkRetries on the client or the request to change that,
or to 0 to turn retries off.
A write without an idempotency key is sent once. The SDK does not retry it,
because it cannot tell whether the first attempt ran.
Retry a write safely
An idempotency key makes a write safe to repeat. The API runs it once and returns the stored result for every repeat with the same key:messages.send, messages.react,
chats.editMessage, chats.deleteMessage, channels.reactToMessage,
campaigns.create, campaigns.launch, campaigns.pause, campaigns.resume,
campaigns.stop, webhooks.test, and operations.cancel.
Read every page
Lists of events, webhooks, webhook deliveries, operations, call records, and call opt-outs return aCursorPage. Loop over it with for await and the SDK
fetches the next pages for you:
items, hasMore, and nextPage():
nextPage() returns null after the last page. page.response.metadata holds
the response metadata.
Some methods return the API’s page envelope directly as { data, page }. Pass
page.nextCursor as cursor while page.hasMore is true: