Save http request when offline


i use $http to send request to our server. Only problem is that sometimes those request can not be done when the phone does not have any connectivity. Instead of aborting/canceling the request with an error message, is there any possible way to save the request and send it again when connectivity is back? for example save every request done in offline mode into an array(or localstorage for example) an execute all the request when the device is back online?

any help would be appreciated.

Kind regards

You could do a $http interceptor (check$http) to save the requests

Then with ngCordova listen to $cordovaNetwork:online event, and then do the logic to process that requests

Thanks for your tip @soutlink , i’ve been using interceptors before, but how would you save your request ?
can i find an example of it somewhere?

thank you

What about this?

Another option is to decorate $http to handle request, or create your own service that wrap $http calls, and to the log logic

1 Like

Awesome @soutlink, thats just perfect! thank you!