Package kong.unirest.core
Class FailedResponse<T>
- java.lang.Object
-
- kong.unirest.core.FailedResponse<T>
-
- All Implemented Interfaces:
HttpResponse<T>
public class FailedResponse<T> extends Object implements 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
-
-
Constructor Summary
Constructors Constructor Description FailedResponse(Exception e)
Build a elaborate lie from a failure.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
getBody()
Cookies
getCookies()
return a cookie collection parse from the set-cookie headerHeaders
getHeaders()
Optional<UnirestParsingException>
getParsingError()
If the transformation to the body failed by an exception it will be kept hereHttpRequestSummary
getRequestSummary()
int
getStatus()
Returns a 542, which is nothing and a lie.String
getStatusText()
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.HttpResponse<T>
ifFailure(Consumer<HttpResponse<T>> consumer)
If the response was NOT a 200-series response or a mapping exception happened.HttpResponse<T>
ifSuccess(Consumer<HttpResponse<T>> consumer)
If the response was a 200-series response.boolean
isSuccess()
is this a success? Obvs no!<V> HttpResponse<V>
map(Function<T,V> func)
Map the Response into another response with a different body<V> V
mapBody(Function<T,V> func)
Map the body into another type<E> E
mapError(Class<? extends E> errorClass)
Map the body to an error object, however because the body in this case is always null this will always return null
-
-
-
Constructor Detail
-
FailedResponse
public FailedResponse(Exception e)
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 Detail
-
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
public String getStatusText()
a error message of the exception- Specified by:
getStatusText
in interfaceHttpResponse<T>
- Returns:
- a 'status' message
-
getHeaders
public Headers getHeaders()
- Specified by:
getHeaders
in interfaceHttpResponse<T>
- Returns:
- a empty headers object because none was returned because there was no return
-
getBody
public T getBody()
- Specified by:
getBody
in interfaceHttpResponse<T>
- Returns:
- null, because there was no response
-
getParsingError
public Optional<UnirestParsingException> 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
public <V> V mapBody(Function<T,V> func)
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
public <V> HttpResponse<V> map(Function<T,V> func)
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
public HttpResponse<T> ifSuccess(Consumer<HttpResponse<T>> consumer)
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
public HttpResponse<T> ifFailure(Consumer<HttpResponse<T>> consumer)
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
public <E> E mapError(Class<? extends E> errorClass)
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
public Cookies 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
public HttpRequestSummary getRequestSummary()
- Specified by:
getRequestSummary
in interfaceHttpResponse<T>
- Returns:
- a Summary of the HttpRequest that created this response
-
-