I'm trying to find a good design pattern, or perhaps series of patterns, for injecting error handling and retry handling when getting data from a webservice.
For instance, I have:
do {
//get the data here
data = Datagetter.getMyData(request)
if(data.hasError())
{
//handle error
}
} while(shouldRetry());
And I am trying to figure out a way to inject the mechanism the discovers and deals with any error, as well as the mechanism that handles how retrying works (should I wait? have I retried enough? should I modify a request parameter? etc).
I would guess I am not the first person faced with this, and there is a way to do this I just haven't discovered yet.
I have looked into chain-of-responsibility and strategy as possible solutions, but I can't seem to quite finagle them to work.
promise
that will be resolved more than once if required. Thepromise
success callback is only executed if the resource is resolved during any attempt (only once), but theerror
callback is only called after all attempts fail.