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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncode()Returns the canonical error code.Returns the HTTP status when the error came from a response.static BetterStackExceptionof(ErrorCode code, String message, Integer httpStatus, String requestId, boolean retryable, Duration retryAfter, Throwable cause) Likeof(ErrorCode, String, Integer, String, Duration, Throwable)with an explicitretryableflag instead of the default of the code.static BetterStackExceptionof(ErrorCode code, String message, Integer httpStatus, String requestId, Duration retryAfter, Throwable cause) Creates the subclass that matchescode.Returns the vendor request id header of the failed response.booleanReturns whether retrying the same call may succeed.Returns the wait the server asked for (Retry-After).Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
BetterStackException
protected BetterStackException(ErrorCode code, String message, Integer httpStatus, String requestId, boolean retryable, Duration retryAfter, Throwable cause) Creates an exception. Prefer the subclasses orof(codes.grow.packages.betterstack.core.ErrorCode, java.lang.String, java.lang.Integer, java.lang.String, java.time.Duration, java.lang.Throwable).- Parameters:
code- canonical codemessage- redacted human texthttpStatus- HTTP status, may be nullrequestId- vendor request id, may be nullretryable- whether retrying the same call may succeedretryAfter- server-requested wait, may be nullcause- underlying error, may be null
-
-
Method Details
-
of
public static BetterStackException of(ErrorCode code, String message, Integer httpStatus, String requestId, Duration retryAfter, Throwable cause) Creates the subclass that matchescode.- Parameters:
code- canonical codemessage- redacted human texthttpStatus- HTTP status, may be nullrequestId- vendor request id, may be nullretryAfter- server-requested wait, may be nullcause- 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) Likeof(ErrorCode, String, Integer, String, Duration, Throwable)with an explicitretryableflag instead of the default of the code.- Parameters:
code- canonical codemessage- redacted human texthttpStatus- HTTP status, may be nullrequestId- vendor request id, may be nullretryable- whether retrying the same call may succeedretryAfter- server-requested wait, may be nullcause- underlying error, may be null- Returns:
- a new exception of the matching subclass
-
code
Returns the canonical error code.- Returns:
- the code
-
httpStatus
Returns the HTTP status when the error came from a response.- Returns:
- the status, or empty
-
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
Returns the wait the server asked for (Retry-After).- Returns:
- the duration, or empty
-