RESTe icon indicating copy to clipboard operation
RESTe copied to clipboard

Skip property in beforeLoad callback

Open m1ga opened this issue 1 year ago • 0 comments

Adding a skip property in the beforeLoad/post callback. With this I can run:

beforeSend: function(data, callback) {
	if (Ti.Network.online) {
		callback(data);
	} else {
		alert("No internet connection!");
		callback({
			skip: true,
			error: "no_internet"
		});
		// will call your success method and pass `error:no_internet` to it
	}
}

it it will call still the success method of my api call but without making the request (no internet!). Inside the success I can hide a loader and use local data for example.

api.getEvents({}, function(data) {
  if (data.error && data.error == "no_internet") {
    // do local stuff
  } else {
    // do normal stuff
  }
});

I'm using this in my app already and it works fine.


Also adding some minor changes to the README

m1ga avatar Aug 20 '22 13:08 m1ga