Error handling
The SDK throws custom unchecked exception types:-
TelnyxServiceException: Base class for HTTP errors. See this table for which exception subclass is thrown for each HTTP status code: -
TelnyxIoException: I/O networking errors. -
TelnyxRetryableException: Generic error indicating a failure that could be retried by the client. -
TelnyxInvalidDataException: Failure to interpret successfully parsed data. For example, when accessing a property that’s supposed to be required, but the API unexpectedly omitted it from the response. -
TelnyxException: Base class for all exceptions. Most errors will result in one of the previously mentioned ones, but completely generic errors may be thrown using the base class.
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
maxRetries method:
Timeouts
Requests time out after 1 minute by default. To set a custom timeout, configure the method call using thetimeout method:
Proxies
To route requests through a proxy, configure the client using theproxy 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:telnyx-java-core- Contains core SDK logic
- Does not depend on OkHttp
- Exposes
TelnyxClient,TelnyxClientAsync,TelnyxClientImpl, andTelnyxClientAsyncImpl, all of which can work with any HTTP client
telnyx-java-client-okhttp- Depends on OkHttp
- Exposes
TelnyxOkHttpClientandTelnyxOkHttpClientAsync, which provide a way to constructTelnyxClientImplandTelnyxClientAsyncImpl, respectively, using OkHttp
telnyx-java- Depends on and exposes the APIs of both
telnyx-java-coreandtelnyx-java-client-okhttp - Does not have its own logic
- Depends on and exposes the APIs of both
Customized OkHttpClient
[!TIP] Try the available network options before replacing the default client.To use a customized
OkHttpClient:
- Replace your
telnyx-javadependency withtelnyx-java-core - Copy
telnyx-java-client-okhttp’sOkHttpClientclass into your code and customize it - Construct
TelnyxClientImplorTelnyxClientAsyncImpl, similarly toTelnyxOkHttpClientorTelnyxOkHttpClientAsync, using your customized client
Completely custom HTTP client
To use a completely custom HTTP client:- Replace your
telnyx-javadependency withtelnyx-java-core - Write a class that implements the
HttpClientinterface - Construct
TelnyxClientImplorTelnyxClientAsyncImpl, similarly toTelnyxOkHttpClientorTelnyxOkHttpClientAsync, using your new client class