Package com.guinetik.rr.api
Class ApiException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- com.guinetik.rr.http.RocketRestException
-
- com.guinetik.rr.api.ApiException
-
- All Implemented Interfaces:
Serializable
public class ApiException extends RocketRestException
Exception thrown when an API request fails with rich error details.This exception extends
RocketRestExceptionand provides additional context about API failures including the error message from the server. Use this when you need more details than the base exception provides.Exception Hierarchy
RuntimeException └── RocketRestException (base HTTP exception) ├── CircuitBreakerOpenException ├── TokenExpiredException └── ApiException (richer error details) └── errorMessage: Server error messageHandling ApiException
try { User user = client.get("/users/999", User.class); } catch (ApiException e) { System.err.println("Status: " + e.getStatusCode()); System.err.println("Message: " + e.getErrorMessage()); System.err.println("Body: " + e.getResponseBody()); } catch (RocketRestException e) { // Handles all other HTTP exceptions System.err.println("HTTP error: " + e.getStatusCode()); }Avoiding Exceptions with Result Pattern
Consider using the fluent API with
Resultto avoid exceptions:Result<User, ApiError> result = client.fluent().get("/users/999", User.class); result.match( user -> handleSuccess(user), error -> handleError(error) // No exception thrown );- Since:
- 1.0.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
RocketRestException,Result,ApiError, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ApiException(String message)Creates a new ApiException with just a message.ApiException(String message, String responseBody, String errorMessage, int statusCode)Creates a new ApiException with full error details.ApiException(String message, Throwable cause)Creates a new ApiException with a message and cause.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetErrorMessage()Gets the parsed error message from the server response.-
Methods inherited from class com.guinetik.rr.http.RocketRestException
getResponseBody, getStatusCode
-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
ApiException
public ApiException(String message, String responseBody, String errorMessage, int statusCode)
Creates a new ApiException with full error details.- Parameters:
message- The exception messageresponseBody- The raw response body from the servererrorMessage- The parsed error message from the serverstatusCode- The HTTP status code
-
ApiException
public ApiException(String message)
Creates a new ApiException with just a message.- Parameters:
message- The exception message
-
-
Method Detail
-
getErrorMessage
public String getErrorMessage()
Gets the parsed error message from the server response. This is often a more user-friendly message extracted from the response body.- Returns:
- The server error message, or null if not available
-
-