Class ExceptionUtils

java.lang.Object
pro.mypvit.exceptions.ExceptionUtils

public class ExceptionUtils extends Object
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 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 a MyPVitException if 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 ApiError object, and throws a custom MyPVitException. 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.