Reputation: 363
Is there a way to for Breeze JS to auto retry in the case of a communications failure? Ideally I want to add a central event handler where based in the response, for example 401 I could prompt the user to re-login and then retry the request, or if its general connection problem give the user the option to Retry or Cancel?
I could add code at each request location to handle this, but that would be a lot of work, ideally this needs to be in a central location.
Upvotes: 1
Views: 142
Reputation: 26406
You could put the retry logic in a request interceptor.
From the breeze docs:
Stock Breeze AJAX adapters offer an extension point, the requestInterceptor. This interceptor gives the developer one last look at each request before the adapter calls the actual AJAX component.
The interceptor takes a single parameter, the requestInfo, and returns nothing.
var requestInfo = {
adapter: this, // this AJAX adapter
config: ..., // the configuration object passed to the wrapped AJAX component
dsaConfig: config, // the config arg from the calling Breeze DataServiceAdapter
success: successFn, // adapter's success callback
error: errorFn // adapter's error callback
}
Your request interceptor could wrap the error
callback and add retry logic and 401 handling.
If you're using breeze with jQuery you could do this at a lower level, using jQuery's ajax prefilter.
Upvotes: 1