Package pro.mypvit.exceptions
Class ApiError
java.lang.Object
pro.mypvit.exceptions.ApiError
Represents an error response returned by the API.
This class captures details about errors returned by the API, such as the status code, error message, and additional metadata. It also provides functionality for JSON deserialization.
Key Features:- Encapsulates error details including date, status, and messages.
- Supports deserialization from JSON using a predefined
Gsonconfiguration. - Includes a default constructor for easy instantiation.
String jsonResponse = "{"
+ "\"date\": \"2025-01-01T10:00:00Z\","
+ "\"status_code\": \"400\","
+ "\"error\": \"Bad Request\","
+ "\"message\": \"Invalid request data\","
+ "\"path\": \"/api/transaction\","
+ "\"messages\": [\"Field 'amount' is required\"],"
+ "\"errors\": {\"amount\": \"Must be greater than 0\"}"
+ "}";
ApiError error = ApiError.fromJson(jsonResponse);
System.out.println("Error: " + error.getMessage());
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ApiError
public ApiError()Default constructor for creating an emptyApiErrorinstance.
-
-
Method Details
-
fromJson
Converts a JSON string into anApiErrorinstance.- Parameters:
json- The JSON string to deserialize.- Returns:
- An
ApiErrorinstance populated with data from the JSON string.
-