Interface ResponseFunction

All Known Implementing Classes:
CompositeTransformer, EmptyResponseTransformer, ResumingTransformer, RetryingTransformer

@Experimental public interface ResponseFunction
A transformation function used while processing DiscordWebRequest objects.

Using ResponseFunction objects is targeted to supporting Router implementations that allow enrichment of a response Mono pipeline, allowing cross-cutting behavior for specialized error handling or retrying under specific conditions like an HTTP status code or a given API request route. Usage beyond this concern is not supported and could interfere with downstream operations.

Typical ResponseFunction usage is through RouterOptions, where it can be applied using one of the static helper methods defined in this class.

  • Method Details

    • transform

      Transform a Mono pipeline using the given DiscordWebRequest as hint for parameterization of the resulting transformation.
      Parameters:
      request - the DiscordRequest used for the targeted Mono sequence
      Returns:
      a Function that allows immediately mapping this Mono into a target Mono instance
    • emptyIfNotFound

      static EmptyResponseTransformer emptyIfNotFound()
      Transform every HTTP 404 status code into an empty response into an empty sequence, effectively suppressing the ClientException that would be forwarded otherwise. See emptyIfNotFound(RouteMatcher) for an override that supports applying the transformation to a subset of requests.
      Returns:
      a ResponseFunction that transforms any HTTP 404 error into an empty sequence
    • emptyIfNotFound

      static EmptyResponseTransformer emptyIfNotFound(RouteMatcher routeMatcher)
      Transforms HTTP 404 status codes caused by requests matching the given RouteMatcher into an empty sequence, effectively suppressing the ClientException that would be forwarded otherwise. See emptyIfNotFound() to apply this transformation across all Router requests.
      Parameters:
      routeMatcher - the RouteMatcher determining whether to match a particular request
      Returns:
      a ResponseFunction that transforms matching HTTP 404 errors into an empty sequence
    • emptyOnErrorStatus

      static EmptyResponseTransformer emptyOnErrorStatus(RouteMatcher routeMatcher, Integer... codes)
      Transforms the given error status codes caused by requests matching the given RouteMatcher, effectively suppressing the ClientException that would be forwarded otherwise.

      Only a subset of HTTP status codes is supported, like all the ones from 400 and 500 series, except for the 429 (Too Many Requests) error that is handled upstream.

      Parameters:
      routeMatcher - the RouteMatcher determining whether to match a particular request
      codes - the list of HTTP status codes to match when applying this transformation
      Returns:
      a ResponseFunction that transforms matching requests and response statuses into an empty sequence
    • retryOnceOnErrorStatus

      static RetryingTransformer retryOnceOnErrorStatus(Integer... codes)
      Applies a retry strategy to retry once with a fixed backoff of 1 second to the given error status codes caused by any request, effectively suppressing the ClientException that would be forwarded otherwise.

      Only a subset of HTTP status codes is supported, like all the ones from 400 and 500 series, except for the 429 (Too Many Requests) error that is handled upstream.

      Please note that if you specify error codes 502, 503 or 504 you will replace a built-in retry factory that handles Discord service errors using an exponential backoff with jitter strategy.

      Parameters:
      codes - the list of HTTP status codes to match when applying this transformation
      Returns:
      a ResponseFunction that transforms matching response statuses into sequence that retries the request once after waiting 1 second.
    • retryOnceOnErrorStatus

      static RetryingTransformer retryOnceOnErrorStatus(RouteMatcher routeMatcher, Integer... codes)
      Applies a retry strategy to retry once with a fixed backoff of 1 second to the given error status codes caused by requests matching the given RouteMatcher, effectively suppressing the ClientException that would be forwarded otherwise.

      Only a subset of HTTP status codes is supported, like all the ones from 400 and 500 series, except for the 429 (Too Many Requests) error that is handled upstream.

      Please note that if you specify error codes 502, 503 or 504 you will replace a built-in retry factory that handles Discord service errors using an exponential backoff with jitter strategy.

      Parameters:
      routeMatcher - the RouteMatcher determining whether to match a particular request
      codes - the list of HTTP status codes to match when applying this transformation
      Returns:
      a ResponseFunction that transforms matching response statuses into sequence that retries the request once after waiting 1 second.
    • retryWhen

      static RetryingTransformer retryWhen(RouteMatcher routeMatcher, Retry retry)
      Applies a custom retry strategy to the requests matching the given RouteMatcher, effectively suppressing the ClientException that would be forwarded otherwise.

      Care must be taken when applying this transformation while using a long running retry factory, as it may effectively block further requests on the same rate limiting bucket.

      Parameters:
      routeMatcher - the RouteMatcher determining whether to match a particular request
      retry - the Retry factory to install while applying this transformation
      Returns:
      a ResponseFunction that transforms matching response statuses into sequence that retries the request once after waiting 1 second.