Class BetterStackException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
codes.grow.packages.betterstack.core.BetterStackException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AuthenticationException, CancelledException, ConfigException, ConflictException, NotFoundException, PermissionDeniedException, RateLimitException, TimeoutException, UnavailableException, UnsupportedException, ValidationException

public class BetterStackException extends RuntimeException
Base class of every error raised by the Better Stack Logs SDK (SPEC section 2.1).

The message never contains secrets, tokens, request bodies or unfiltered response bodies. Catch a subclass (for example NotFoundException) or switch on code().

See Also:
  • Constructor Details

  • Method Details

    • of

      public static BetterStackException of(ErrorCode code, String message, Integer httpStatus, String requestId, Duration retryAfter, Throwable cause)
      Creates the subclass that matches code.
      Parameters:
      code - canonical code
      message - redacted human text
      httpStatus - HTTP status, may be null
      requestId - vendor request id, may be null
      retryAfter - server-requested wait, may be null
      cause - underlying error, may be null
      Returns:
      a new exception of the matching subclass
    • of

      public static BetterStackException of(ErrorCode code, String message, Integer httpStatus, String requestId, boolean retryable, Duration retryAfter, Throwable cause)
      Like of(ErrorCode, String, Integer, String, Duration, Throwable) with an explicit retryable flag instead of the default of the code.
      Parameters:
      code - canonical code
      message - redacted human text
      httpStatus - HTTP status, may be null
      requestId - vendor request id, may be null
      retryable - whether retrying the same call may succeed
      retryAfter - server-requested wait, may be null
      cause - underlying error, may be null
      Returns:
      a new exception of the matching subclass
    • code

      public ErrorCode code()
      Returns the canonical error code.
      Returns:
      the code
    • httpStatus

      public OptionalInt httpStatus()
      Returns the HTTP status when the error came from a response.
      Returns:
      the status, or empty
    • requestId

      public Optional<String> requestId()
      Returns the vendor request id header of the failed response.
      Returns:
      the request id, or empty
    • retryable

      public boolean retryable()
      Returns whether retrying the same call may succeed.
      Returns:
      true for rate limits, unavailability and timeouts
    • retryAfter

      public Optional<Duration> retryAfter()
      Returns the wait the server asked for (Retry-After).
      Returns:
      the duration, or empty