Class FailedResponse<T>

  • All Implemented Interfaces:
    HttpResponse<T>

    public class FailedResponse<T>
    extends java.lang.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Exception failureReason  
    • Constructor Summary

      Constructors 
      Constructor Description
      FailedResponse​(java.lang.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 header
      Headers getHeaders()  
      java.util.Optional<UnirestParsingException> getParsingError()
      If the transformation to the body failed by an exception it will be kept here
      HttpRequestSummary getRequestSummary()  
      int getStatus()
      Returns a 542, which is nothing and a lie.
      java.lang.String getStatusText()
      a error message of the exception
      <E> HttpResponse<T> ifFailure​(java.lang.Class<? extends E> errorClass, java.util.function.Consumer<HttpResponse<E>> consumer)
      If the response was NOT a 200-series response or a mapping exception happened.
      HttpResponse<T> ifFailure​(java.util.function.Consumer<HttpResponse<T>> consumer)
      If the response was NOT a 200-series response or a mapping exception happened.
      HttpResponse<T> ifSuccess​(java.util.function.Consumer<HttpResponse<T>> consumer)
      If the response was a 200-series response.
      boolean isSuccess()
      is this a success? Obvs no!
      <V> HttpResponse<V> map​(java.util.function.Function<T,​V> func)
      Map the Response into another response with a different body
      <V> V mapBody​(java.util.function.Function<T,​V> func)
      Map the body into another type
      <E> E mapError​(java.lang.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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • failureReason

        private final java.lang.Exception failureReason
    • Constructor Detail

      • FailedResponse

        public FailedResponse​(java.lang.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 java.lang.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
      • getParsingError

        public java.util.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 interface HttpResponse<T>
        Returns:
        a parsing exception with the exception.
      • mapBody

        public <V> V mapBody​(java.util.function.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​(java.util.function.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​(java.util.function.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​(java.util.function.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​(java.lang.Class<? extends E> errorClass,
                                             java.util.function.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​(java.lang.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