Skip to content

Error Handling

Garvit Joshi edited this page Apr 2, 2026 · 3 revisions

Error Handling

All send(...) methods are synchronous. On success, they return the Tremor fingerprint assigned by the server.

Failure Types

Failure type Exception
Invalid client configuration or event payload IllegalArgumentException
Network or transport failure TremorClientException
Non-2xx response from Tremor TremorApiException
Invalid or malformed JSON during request/response handling TremorSerializationException

TremorApiException

TremorApiException is used when Tremor responds but rejects the request.

It carries:

  • HTTP status code
  • response body
  • request URL

Example:

String tremorKey = "...";

try (TremorClient client = TremorClient.builder(tremorKey).build()) {
    client.send(new IllegalStateException("checkout failed"));
} catch (TremorApiException e) {
    System.err.println(e.getStatusCode());
    System.err.println(e.getResponseBody());
    System.err.println(e.getUrl());
}

TremorClientException

TremorClientException wraps transport failures such as:

  • connection refused
  • timeouts
  • connection reset
  • DNS failures

Use this when the request could not be completed at all.

TremorSerializationException

TremorSerializationException is raised when:

  • the event cannot be serialized
  • the success response is not valid JSON
  • the response does not contain fingerprint
  • the response fingerprint is blank

Validation Failures

Validation failures happen before the HTTP request is executed.

Examples:

  • blank client key
  • null event
  • null throwable
  • missing error.className
  • missing error.message
  • too many tags
  • invalid structured custom data depth

These failures use IllegalArgumentException.

Catching Failures Cleanly

String tremorKey = "...";

try (TremorClient client =
    TremorClient.builder(tremorKey).baseUrl("https://tremor.example.com/tremor").build()) {
    String fingerprint = client.send(new IllegalStateException("checkout failed"));
} catch (TremorApiException e) {
    // Tremor rejected the request
} catch (TremorClientException e) {
    // Transport problem
} catch (IllegalArgumentException e) {
    // Local configuration or payload problem
}

reportAndSuppress Behavior

reportAndSuppress(...) is different by design:

  • it catches Exception
  • it tries to report the failure
  • it suppresses the original exception
  • it suppresses reporting failures too

Use it only when swallowing the execution failure is intentional.

Clone this wiki locally