Package pro.mypvit.exceptions
Class ExceptionUtils
java.lang.Object
pro.mypvit.exceptions.ExceptionUtils
Utility class for handling API errors in the MyPVit SDK.
This class provides functionality to process HTTP responses, identify API errors, and throw custom exceptions with detailed information. It also includes logging for debugging purposes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidhandleApiError(okhttp3.Response response) Handles API errors by inspecting the HTTP response and throwing aMyPVitExceptionif an error is detected.
-
Constructor Details
-
ExceptionUtils
public ExceptionUtils()Default constructor
-
-
Method Details
-
handleApiError
public static void handleApiError(okhttp3.Response response) Handles API errors by inspecting the HTTP response and throwing aMyPVitExceptionif an error is detected.If the response indicates a failure (non-2xx status), this method extracts the error details from the response body, converts it into an
ApiErrorobject, and throws a customMyPVitException. It also logs the error details to the console.- Parameters:
response- The HTTP response to check.- Throws:
MyPVitException- If the response indicates an API error.RuntimeException- If an I/O error occurs while reading the response body.
-