Last active
December 15, 2015 18:28
-
-
Save jcblw/5303607 to your computer and use it in GitHub Desktop.
how to handle errors with api constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you dont need new but can have new | |
var api = apiConstructor(); | |
var success = function(res){ | |
console.log(res); | |
}; | |
//passes error object eg. -> new Error("this is an error") | |
var error = function(err){ | |
console.log(err.message); | |
}; | |
api.addCommand('user/check_urlname'). | |
addCall({ | |
'url_name' : url_name | |
}). | |
sendData(); | |
// error is the second parameter | |
api.complete(success, error); | |
// mainly handles could not recieve json | |
// also now you can stop api calls if user navigates away from data being loaded | |
// this is just a eg. | |
nav.onChange = function(){ | |
// this is the actual call | |
api.cancel(); | |
// then you can start another call | |
api.addCommand('user/check_urlname'). | |
addCall({ | |
'url_name' : url_name | |
}).sendData(); | |
api.complete(success, error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment