Skip to main content
Every error the API returns as an HTTP response is thrown as RoutaApiError or one of its subclasses. They all carry:

Error classes

RoutaBillingError and RoutaConflictError exist from 0.3.0. Both extend RoutaApiError, so a catch on RoutaApiError still catches these errors.
A subclass is also a RoutaApiError. Test the most specific subclasses first, as in the example above.

Handling business cases

Use the code to decide what to do, not the message text.
Do not schedule automatic retries for a 402: waiting does not increase the allowance. The SDK does not retry it either. See Plans and allowance.

Malformed requests and reasons

A 422 with the request_invalid code means the request does not have the documented format: a field is missing or has the wrong type, which can happen with values that reach the SDK untyped. param is the field, with the API names (template.button_parameters.0.index), and is undefined when none can be pointed at. details carries what a program can use, with keys that depend on the code. In several errors, details.reason tells apart the causes behind one code. Check the type of the value before you use it:
See the values in Reasons for each code.

Billing errors

A 402 arrives as a RoutaBillingError. Use the code to tell the cases apart. The numbers only exist on the codes that set them, and are undefined on the others.
A test project is not refused for billing when it sends messages.

Conflicts

A 409 arrives as a RoutaConflictError. When the API says so, reason tells what blocks the operation. Today this applies to project_not_deletable in the Partner API, with has_enabled_channel or last_project. The idempotency conflicts (idempotency_key_reuse and idempotency_in_progress) are also 409. See Idempotency.

What the SDK already retries

Network failures, 429, 5xx and a 409 idempotency_in_progress are retried automatically, up to maxRetries times. Only the final error reaches your catch. 401, 402, 403, 404 and 422 are never retried, and no 409 other than idempotency_in_progress is retried. See Configuration.

What is not a RoutaApiError

Two situations do not go through these classes:
  • Network failures and timeouts, once the retries run out, reject with a plain Error whose name is 'HttpRequestError'. The class is not exported yet, so check error.name instead of using instanceof.
  • Invalid configuration, such as an empty apiKey, throws a plain synchronous Error in the Routa constructor.
A 413 (body too large on a media upload) arrives as a base RoutaApiError, with statusCode 413, and is not retried.

Delivery failures

A provider failure does not become an exception in messages.send(): the message is accepted and the failure shows up later, asynchronously, as the message.failed event. The RoutaProviderError class exists for future use, and no code in the SDK throws it today.