@Experimental public interface ResponseFunction
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.
Modifier and Type | Method and Description |
---|---|
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. |
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. |
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. |
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. |
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. |
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. |
Function<Mono<ClientResponse>,Mono<ClientResponse>> |
transform(DiscordWebRequest request)
Transform a
Mono pipeline using the given DiscordWebRequest as hint for parameterization of the
resulting transformation. |
Function<Mono<ClientResponse>,Mono<ClientResponse>> transform(DiscordWebRequest request)
Mono
pipeline using the given DiscordWebRequest
as hint for parameterization of the
resulting transformation.request
- the DiscordRequest
used for the targeted Mono
sequenceFunction
that allows immediately mapping this Mono
into a target Mono
instancestatic EmptyResponseTransformer emptyIfNotFound()
ClientException
that would be forwarded otherwise. See emptyIfNotFound(RouteMatcher)
for an override that supports applying the transformation to a subset of requests.ResponseFunction
that transforms any HTTP 404 error into an empty sequencestatic EmptyResponseTransformer emptyIfNotFound(RouteMatcher routeMatcher)
RouteMatcher
into an empty
sequence, effectively suppressing the ClientException
that would be forwarded otherwise. See
emptyIfNotFound()
to apply this transformation across all Router
requests.routeMatcher
- the RouteMatcher
determining whether to match a particular requestResponseFunction
that transforms matching HTTP 404 errors into an empty sequencestatic EmptyResponseTransformer emptyOnErrorStatus(RouteMatcher routeMatcher, Integer... codes)
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.
routeMatcher
- the RouteMatcher
determining whether to match a particular requestcodes
- the list of HTTP status codes to match when applying this transformationResponseFunction
that transforms matching requests and response statuses into an empty sequencestatic RetryingTransformer retryOnceOnErrorStatus(Integer... codes)
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.
codes
- the list of HTTP status codes to match when applying this transformationResponseFunction
that transforms matching response statuses into sequence that retries the
request once after waiting 1 second.static RetryingTransformer retryOnceOnErrorStatus(RouteMatcher routeMatcher, Integer... codes)
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.
routeMatcher
- the RouteMatcher
determining whether to match a particular requestcodes
- the list of HTTP status codes to match when applying this transformationResponseFunction
that transforms matching response statuses into sequence that retries the
request once after waiting 1 second.static RetryingTransformer retryWhen(RouteMatcher routeMatcher, Retry<?> retry)
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.
routeMatcher
- the RouteMatcher
determining whether to match a particular requestretry
- the Retry
factory to install while applying this transformationResponseFunction
that transforms matching response statuses into sequence that retries the
request once after waiting 1 second.