Interface ResponseFunction
- All Known Implementing Classes:
CompositeTransformer,EmptyResponseTransformer,ResumingTransformer,RetryingTransformer
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 Summary
Modifier and TypeMethodDescriptionstatic EmptyResponseTransformerTransform every HTTP 404 status code into an empty response into an empty sequence, effectively suppressing theClientExceptionthat would be forwarded otherwise.static EmptyResponseTransformeremptyIfNotFound(RouteMatcher routeMatcher) Transforms HTTP 404 status codes caused by requests matching the givenRouteMatcherinto an empty sequence, effectively suppressing theClientExceptionthat would be forwarded otherwise.static EmptyResponseTransformeremptyOnErrorStatus(RouteMatcher routeMatcher, Integer... codes) Transforms the given error status codes caused by requests matching the givenRouteMatcher, effectively suppressing theClientExceptionthat would be forwarded otherwise.static RetryingTransformerretryOnceOnErrorStatus(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 givenRouteMatcher, effectively suppressing theClientExceptionthat would be forwarded otherwise.static RetryingTransformerretryOnceOnErrorStatus(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 theClientExceptionthat would be forwarded otherwise.static RetryingTransformerretryWhen(RouteMatcher routeMatcher, Retry retry) Applies a custom retry strategy to the requests matching the givenRouteMatcher, effectively suppressing theClientExceptionthat would be forwarded otherwise.transform(DiscordWebRequest request) Transform aMonopipeline using the givenDiscordWebRequestas hint for parameterization of the resulting transformation.
-
Method Details
-
transform
Transform aMonopipeline using the givenDiscordWebRequestas hint for parameterization of the resulting transformation.- Parameters:
request- theDiscordRequestused for the targetedMonosequence- Returns:
- a
Functionthat allows immediately mapping thisMonointo a targetMonoinstance
-
emptyIfNotFound
Transform every HTTP 404 status code into an empty response into an empty sequence, effectively suppressing theClientExceptionthat would be forwarded otherwise. SeeemptyIfNotFound(RouteMatcher)for an override that supports applying the transformation to a subset of requests.- Returns:
- a
ResponseFunctionthat transforms any HTTP 404 error into an empty sequence
-
emptyIfNotFound
Transforms HTTP 404 status codes caused by requests matching the givenRouteMatcherinto an empty sequence, effectively suppressing theClientExceptionthat would be forwarded otherwise. SeeemptyIfNotFound()to apply this transformation across allRouterrequests.- Parameters:
routeMatcher- theRouteMatcherdetermining whether to match a particular request- Returns:
- a
ResponseFunctionthat transforms matching HTTP 404 errors into an empty sequence
-
emptyOnErrorStatus
Transforms the given error status codes caused by requests matching the givenRouteMatcher, effectively suppressing theClientExceptionthat 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- theRouteMatcherdetermining whether to match a particular requestcodes- the list of HTTP status codes to match when applying this transformation- Returns:
- a
ResponseFunctionthat transforms matching requests and response statuses into an empty sequence
-
retryOnceOnErrorStatus
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 theClientExceptionthat 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
ResponseFunctionthat transforms matching response statuses into sequence that retries the request once after waiting 1 second.
-
retryOnceOnErrorStatus
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 givenRouteMatcher, effectively suppressing theClientExceptionthat 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- theRouteMatcherdetermining whether to match a particular requestcodes- the list of HTTP status codes to match when applying this transformation- Returns:
- a
ResponseFunctionthat transforms matching response statuses into sequence that retries the request once after waiting 1 second.
-
retryWhen
Applies a custom retry strategy to the requests matching the givenRouteMatcher, effectively suppressing theClientExceptionthat 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- theRouteMatcherdetermining whether to match a particular requestretry- theRetryfactory to install while applying this transformation- Returns:
- a
ResponseFunctionthat transforms matching response statuses into sequence that retries the request once after waiting 1 second.
-