Class HttpSendOutcomeWrapper
java.lang.Object
cf.maybelambda.httpvalidator.springboot.util.HttpSendOutcomeWrapper
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Status code assigned to exceptional send results arising from network errors.static final String
Message about a network error that occurred while attempting a request. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an instance wrapping an exception encountered during the request.Constructs an instance wrapping a successful HTTP response. -
Method Summary
Modifier and TypeMethodDescriptiongetBody()
Gets the body of the HTTP response.int
Gets the status code of the HTTP response.boolean
Checks if the wrapper contains a complete HTTP response with a non-null body.
-
Field Details
-
NET_ERR_CODE
public static final int NET_ERR_CODEStatus code assigned to exceptional send results arising from network errors.- See Also:
-
NET_ERR_MSG
Message about a network error that occurred while attempting a request.- See Also:
-
-
Constructor Details
-
HttpSendOutcomeWrapper
Constructs an instance wrapping a successful HTTP response.- Parameters:
res
- the HTTP response
-
HttpSendOutcomeWrapper
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
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
-