HTTP Post request handling



I am working on an app that is expected to submit data to a remote server. The submit function does an Http Post and the response is handled accordingly.

My question is, what is the best way to handle network failures, offline mode, etc so that once a user has entered data, it is sent to the server, no matter what.

Couple of scenarios would be,

  1. User Online: Http post returns successful.
  2. User Online then lost connection: Http post made but returns error.
  3. User Offline: Save to local storage and try posting when network state changes to online.
  4. Server offline: Try posting data, fail, store back to local storage and try again in a background service.

How to best handle these cases?



What I do is spool requests to ionic-storage for any of your last three cases, and use the Network plugin to inform me when the network becomes connected, at which point I resubmit everything in the spool.