Package kong.unirest.core
Class FailedResponse<T>
java.lang.Object
kong.unirest.core.FailedResponse<T>
- All Implemented Interfaces:
HttpResponse<T>
A failed response you COULD return if you want to live in a house of lies.
This can be returned by a interceptor rather than throwing an exception.
It's possible if not handled correctly this could be more confusing than the exception
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBody()
return a cookie collection parse from the set-cookie headerIf the transformation to the body failed by an exception it will be kept hereint
Returns a 542, which is nothing and a lie.a error message of the exception<E> HttpResponse
<T> ifFailure
(Class<? extends E> errorClass, Consumer<HttpResponse<E>> consumer) If the response was NOT a 200-series response or a mapping exception happened.ifFailure
(Consumer<HttpResponse<T>> consumer) If the response was NOT a 200-series response or a mapping exception happened.ifSuccess
(Consumer<HttpResponse<T>> consumer) If the response was a 200-series response.boolean
is this a success? Obvs no!<V> HttpResponse
<V> Map the Response into another response with a different body<V> V
Map the body into another type<E> E
Map the body to an error object, however because the body in this case is always null this will always return null
-
Field Details
-
failureReason
-
-
Constructor Details
-
FailedResponse
Build a elaborate lie from a failure. Just like what you're going to do at thanksgiving dinner.- Parameters:
e
- where it all went wrong.
-
-
Method Details
-
getStatus
public int getStatus()Returns a 542, which is nothing and a lie. The remove server in this case returned nothing all all. As far as we know you aren't even on the internet. So we made up this code, because a 500+ status is better than 0- Specified by:
getStatus
in interfaceHttpResponse<T>
- Returns:
- 542
-
getStatusText
a error message of the exception- Specified by:
getStatusText
in interfaceHttpResponse<T>
- Returns:
- a 'status' message
-
getHeaders
- Specified by:
getHeaders
in interfaceHttpResponse<T>
- Returns:
- a empty headers object because none was returned because there was no return
-
getBody
- Specified by:
getBody
in interfaceHttpResponse<T>
- Returns:
- null, because there was no response
-
getParsingError
Description copied from interface:HttpResponse
If the transformation to the body failed by an exception it will be kept here- Specified by:
getParsingError
in interfaceHttpResponse<T>
- Returns:
- a parsing exception with the exception.
-
mapBody
Description copied from interface:HttpResponse
Map the body into another type- Specified by:
mapBody
in interfaceHttpResponse<T>
- Type Parameters:
V
- always null- Parameters:
func
- a function to transform a body type to something else.- Returns:
- another object
-
map
Description copied from interface:HttpResponse
Map the Response into another response with a different body- Specified by:
map
in interfaceHttpResponse<T>
- Type Parameters:
V
- always null- Parameters:
func
- a function to transform a body type to something else.- Returns:
- another response
-
ifSuccess
Description copied from interface:HttpResponse
If the response was a 200-series response. Invoke this consumer can be chained with ifFailure- Specified by:
ifSuccess
in interfaceHttpResponse<T>
- Parameters:
consumer
- a function to consume a successful HttpResponse. This is never called in this case.- Returns:
- this HttpResponse.
-
ifFailure
Description copied from interface:HttpResponse
If the response was NOT a 200-series response or a mapping exception happened. Invoke this consumer can be chained with ifSuccess- Specified by:
ifFailure
in interfaceHttpResponse<T>
- Parameters:
consumer
- a function to consume a failed HttpResponse always called in this case- Returns:
- this HttpResponse
-
ifFailure
public <E> HttpResponse<T> ifFailure(Class<? extends E> errorClass, Consumer<HttpResponse<E>> consumer) Description copied from interface:HttpResponse
If the response was NOT a 200-series response or a mapping exception happened. map the original body into a error type and invoke this consumer can be chained with ifSuccess- Specified by:
ifFailure
in interfaceHttpResponse<T>
- Type Parameters:
E
- the type of error class to map the body- Parameters:
errorClass
- the class to transform the body to. However as the body is null in this case it will also be nullconsumer
- a function to consume a failed HttpResponse always called in this case- Returns:
- this HttpResponse
-
isSuccess
public boolean isSuccess()is this a success? Obvs no!- Specified by:
isSuccess
in interfaceHttpResponse<T>
- Returns:
- false
-
mapError
Map the body to an error object, however because the body in this case is always null this will always return null- Specified by:
mapError
in interfaceHttpResponse<T>
- Type Parameters:
E
- the error type- Parameters:
errorClass
- the class for the error- Returns:
- null
-
getCookies
Description copied from interface:HttpResponse
return a cookie collection parse from the set-cookie header- Specified by:
getCookies
in interfaceHttpResponse<T>
- Returns:
- a Cookies collection
-
getRequestSummary
- Specified by:
getRequestSummary
in interfaceHttpResponse<T>
- Returns:
- a Summary of the HttpRequest that created this response
-