Class ClientResponse

java.lang.Object
discord4j.rest.http.client.ClientResponse

public class ClientResponse extends Object
An HTTP response encapsulating status, headers and accessors to the response body for consumption.

Make sure you call bodyToMono(Class), skipBody() or similar and actually consume the response body. It is possible to use bodyToMono(Void.class) if the response is empty.

  • Method Details

    • getHttpResponse

      public HttpClientResponse getHttpResponse()
      Return the underlying HttpClientResponse from where you can access the response headers, status and context.
      Returns:
      this response HttpClientResponse
    • getBody

      public Mono<ByteBuf> getBody()
      Return the body of this response as a Mono of ByteBuf. If this Mono is cancelled, then it will not be possible to consume the body again.
      Returns:
      the response body contents
    • bodyToMono

      public <T> Mono<T> bodyToMono(Class<T> responseType)
      Read the response body and extract it to a single object according to the responseType given. If the response has an HTTP error (status codes 4xx and 5xx) the produced object will be a ClientException.
      Type Parameters:
      T - the response type
      Parameters:
      responseType - the target type this response body should be converted into
      Returns:
      a Mono containing the response body extracted into the given T type. If a network or read error had occurred, it will be emitted through the Mono.
    • createException

      public Mono<ClientException> createException()
      Create a ClientException based on the contents of this response. This method will attempt to extract an ErrorResponse from the body if possible.
      Returns:
      a Mono of ClientException from this response
    • skipBody

      public Mono<Void> skipBody()
      Consume and release the response body then return and empty Mono.
      Returns:
      an empty Mono indicating response body consumption and release
    • toString

      public String toString()
      Overrides:
      toString in class Object