Package com.guinetik.rr.http
Class RocketRestException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- com.guinetik.rr.http.RocketRestException
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ApiException,CircuitBreakerOpenException,TokenExpiredException
public class RocketRestException extends RuntimeException
Base runtime exception for all HTTP-related errors in RocketRest.This exception captures HTTP error details including the status code and response body, making it easier to handle and diagnose API errors. As a RuntimeException, it doesn't require explicit catching, but can be caught for specific error handling.
Exception Hierarchy
RuntimeException └── RocketRestException (base - catch this for all HTTP errors) ├── CircuitBreakerOpenException (circuit breaker is open) ├── TokenExpiredException (401 - token needs refresh) └── ApiException (richer error details from server)Exception Handling
try { User user = client.get("/users/1", User.class); } catch (CircuitBreakerOpenException e) { // Service is down, fail fast System.out.println("Service unavailable, retry in " + e.getEstimatedMillisUntilReset() + "ms"); } catch (TokenExpiredException e) { // Token expired, re-authenticate refreshToken(); } catch (RocketRestException e) { // All other HTTP errors System.err.println("HTTP " + e.getStatusCode() + ": " + e.getMessage()); }Avoiding Exceptions with Fluent API
// Use fluent API to avoid exception handling Result<User, ApiError> result = client.fluent().get("/users/1", User.class); result.match( user -> System.out.println("Found: " + user.getName()), error -> System.out.println("Error " + error.getStatusCode() + ": " + error.getMessage()) );- Since:
- 1.0.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
CircuitBreakerOpenException,TokenExpiredException,ApiException,ApiError, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RocketRestException(String message)Constructs a new exception with the specified detail message.RocketRestException(String message, int statusCode, String responseBody)Constructs a new exception with the specified detail message, status code, and response body.RocketRestException(String message, Throwable cause)Constructs a new exception with the specified detail message and cause.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetResponseBody()Gets the response body.intgetStatusCode()Gets the HTTP status code.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
RocketRestException
public RocketRestException(String message)
Constructs a new exception with the specified detail message.- Parameters:
message- The detail message
-
RocketRestException
public RocketRestException(String message, Throwable cause)
Constructs a new exception with the specified detail message and cause.- Parameters:
message- The detail messagecause- The cause
-
RocketRestException
public RocketRestException(String message, int statusCode, String responseBody)
Constructs a new exception with the specified detail message, status code, and response body.- Parameters:
message- The detail messagestatusCode- The HTTP status coderesponseBody- The response body
-
-
Method Detail
-
getStatusCode
public int getStatusCode()
Gets the HTTP status code.- Returns:
- The HTTP status code
-
getResponseBody
public String getResponseBody()
Gets the response body.- Returns:
- The response body
-
-