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 thecode to decide what to do, not the message text.
Malformed requests and reasons
A422 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:
Billing errors
A402 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.
Conflicts
A409 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
Errorwhosenameis'HttpRequestError'. The class is not exported yet, so checkerror.nameinstead of usinginstanceof. - Invalid configuration, such as an empty
apiKey, throws a plain synchronousErrorin theRoutaconstructor.
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 inmessages.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.