Class ApiError

java.lang.Object
pro.mypvit.exceptions.ApiError

public class ApiError extends Object
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 Gson configuration.
  • Includes a default constructor for easy instantiation.
Usage Example:
 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 Details

    • ApiError

      public ApiError()
      Default constructor for creating an empty ApiError instance.
  • Method Details

    • fromJson

      public static ApiError fromJson(String json)
      Converts a JSON string into an ApiError instance.
      Parameters:
      json - The JSON string to deserialize.
      Returns:
      An ApiError instance populated with data from the JSON string.