Class 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 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 message
        cause - 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 message
        statusCode - The HTTP status code
        responseBody - 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