Add methods to KiwiResponses that accept Response suppliers #1141
Labels
new feature
A new feature such as a new class, method, package, group of classes, etc.
Milestone
Motivation
KiwiResponses
has methods to perform various actions on aResponse
, which means code calling these methods must have already obtained theResponse
using aClient
, and should have handled any (runtime) exceptions that can be thrown, e.g.,ProcessingException
and subclasses.Once the
Response
has been obtained, then the code can call one of theKiwiResponses
methods. This splits the code making request from the code handling the response. Sometimes this might be acceptable and/or desirable but usually these activities happen in one place at the same time.Example
Many times it would be nicer to make the request and process the response in one location. For example, currently you might do something like:
But by changing the first argument to a
Supplier<Response>
and adding a 4th argument which accepts an exception and returns an object, the above code can be changed to:In this example, if the request succeeds, then the response entity is resolved to a
List<Task
and returned.If the request fails (has a status that is not 200 in this case) or if the
Supplier
threw an exception, then an empty list is returned and the code (presumably) performs some kind of notification about the error.And the code ensures that any
Response
(successful or not) is closed. If theSupplier
threw an exception, there is no response to close.New Feature Description
This task adds overloaded
onXxx
,accept
, andapply
methods which accept aSupplier<Response
as the first argument instead of aResponse
. This will allow request/response processing code to be located in one location and not have try/catch blocks followed immediately by aKiwiResponses.onXxx
method.Some of the overloads will add additional parameters, like the above example adds a 4th argument,
Function<RuntimeException, T> exceptionFun
, which accepts aRuntimeException
and must return a result of typeT
.This will increase the surface area of
KiwiResponses
by adding 11 new methods: 9onXxx
methods,accept
, andapply
.The text was updated successfully, but these errors were encountered: