Package kong.unirest

Class 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 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 interface HttpResponse<T>
        Returns:
        542
      • getStatusText

        public String getStatusText()
        a error message of the exception
        Specified by:
        getStatusText in interface HttpResponse<T>
        Returns:
        a 'status' message
      • getHeaders

        public Headers getHeaders()
        Specified by:
        getHeaders in interface HttpResponse<T>
        Returns:
        a empty headers object because none was returned because there was no return
      • getBody

        public T getBody()
        Specified by:
        getBody in interface HttpResponse<T>
        Returns:
        null, because there was no response
      • mapBody

        public <V> V mapBody​(Function<T,​V> func)
        Description copied from interface: HttpResponse
        Map the body into another type
        Specified by:
        mapBody in interface HttpResponse<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 interface HttpResponse<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 interface HttpResponse<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 interface HttpResponse<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 interface HttpResponse<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 null
        consumer - 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 interface HttpResponse<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 interface HttpResponse<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 interface HttpResponse<T>
        Returns:
        a Cookies collection