So my app is using the aurelia-fetch-client, and I have an issue popping up on my live app that I am trying to resolve, and think it can be done by adjusting / using the retry configuration.
I cannot find any examples that uses the new .withRetry way of doing that.
What I am trying to do is to setup to retry 3 times, with a 5 second wait for response.
My application is hosted on the free Azure servers, and I need to be able to wait for the service to spin up if its been a while since it was last accessed and its gotten unloaded. That can be 5 to 10 seconds or so.
I have tried this in the code below, but it ignores the retry settings, and I suspect its because I am not passing a retry function. Is that the case?
I am not sure how I would do that with how I have things setup now. Maybe someone can point me in the right direction.
Here is what I have for configuration:
this.http.configure(config =>
{
let retryConfig = { maxRetries: 3, interval: 5000, strategy: 0};
config
//.useStandardConfiguration()
.withDefaults({
headers:
{
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
}
})
.withBaseUrl(API_SETTINGS.urlManage)
.withRetry(retryConfig);
});
and I have a utility function that wraps my api calls:
requestJSON(url: string, opts: any = null)
{
return this.http.fetch(url, opts)
.then(response =>
{
let clone = response.clone();
this.clones.set(url, clone);
return Promise.all([response, response.json()]);
})
.then(([response, json]) =>
{
if (!response.ok)
{
throw new Error(json.message);
}
this.clones.delete(url);
return json;
})
.catch(async exception =>
{
let tmp = await this.clones.get(url);
let txt = tmp ? tmp.text() : undefined;
let msg = new Map([
[TypeError, "There was a problem fetching the response."],
[SyntaxError, "There was a problem parsing the response."],
[Error, exception.message]]).get(exception.constructor);
logger.error(`${msg} [${url}] [${txt}]`);
if(tmp)
{
this.clones.delete(url);
}
toastr.error("Unable to retrieve data. Please check that your login has not timed out. Returning to Home page.", "Error", { timeOut: 5000 });
this.router.navigateToRoute("home");
//return undefined;
});
}