Class HttpSendOutcomeWrapper

java.lang.Object
cf.maybelambda.httpvalidator.springboot.util.HttpSendOutcomeWrapper

public class HttpSendOutcomeWrapper extends Object
A utility wrapper class for handling outcomes of HTTP requests.

This class encapsulates either a successful HTTP response or an exception encountered during the request. It provides methods to query the state of the outcome and to retrieve relevant details.

  • Field Details

    • NET_ERR_CODE

      public static final int NET_ERR_CODE
      Status code assigned to exceptional send results arising from network errors.
      See Also:
    • NET_ERR_MSG

      public static final String NET_ERR_MSG
      Message about a network error that occurred while attempting a request.
      See Also:
  • Constructor Details

    • HttpSendOutcomeWrapper

      public HttpSendOutcomeWrapper(HttpResponse<String> res)
      Constructs an instance wrapping a successful HTTP response.
      Parameters:
      res - the HTTP response
    • HttpSendOutcomeWrapper

      public HttpSendOutcomeWrapper(Throwable ex)
      Constructs an instance wrapping an exception encountered during the request.
      Parameters:
      ex - the exception
  • Method Details

    • isWholeResponse

      public boolean isWholeResponse()
      Checks if the wrapper contains a complete HTTP response with a non-null body.
      Returns:
      true if the response and its body are non-null, false otherwise
    • getStatusCode

      public int getStatusCode()
      Gets the status code of the HTTP response.

      If an exception was encountered during the request, this method returns -1.

      Returns:
      the HTTP status code or -1 if an exception occurred
    • getBody

      public String getBody()
      Gets the body of the HTTP response.

      If an exception was encountered during the request, this method returns a predefined network error message.

      Returns:
      the body of the HTTP response or a network error message if an exception occurred