Skip to main content

Error handling

The SDK throws custom unchecked exception types:

Network options

Retries

The SDK automatically retries 2 times by default, with a short exponential backoff between requests. Only the following error types are retried:
  • Connection errors (for example, due to a network connectivity problem)
  • 408 Request Timeout
  • 409 Conflict
  • 429 Rate Limit
  • 5xx Internal
The API may also explicitly instruct the SDK to retry or not retry a request. To set a custom number of retries, configure the client using the maxRetries method:

Timeouts

Requests time out after 1 minute by default. To set a custom timeout, configure the method call using the timeout method:
Or configure the default for all method calls at the client level:

Proxies

To route requests through a proxy, configure the client using the proxy method:

HTTPS

[!NOTE] Most applications should not call these methods, and instead use the system defaults. The defaults include special optimizations that can be lost if the implementations are modified.
To configure how HTTPS connections are secured, configure the client using the sslSocketFactory, trustManager, and hostnameVerifier methods:

Custom HTTP client

The SDK consists of three artifacts: This structure allows replacing the SDK’s default HTTP client without pulling in unnecessary dependencies.

Customized OkHttpClient

[!TIP] Try the available network options before replacing the default client.
To use a customized OkHttpClient:
  1. Replace your telnyx-java dependency with telnyx-java-core
  2. Copy telnyx-java-client-okhttp’s OkHttpClient class into your code and customize it
  3. Construct TelnyxClientImpl or TelnyxClientAsyncImpl, similarly to TelnyxOkHttpClient or TelnyxOkHttpClientAsync, using your customized client

Completely custom HTTP client

To use a completely custom HTTP client:
  1. Replace your telnyx-java dependency with telnyx-java-core
  2. Write a class that implements the HttpClient interface
  3. Construct TelnyxClientImpl or TelnyxClientAsyncImpl, similarly to TelnyxOkHttpClient or TelnyxOkHttpClientAsync, using your new client class