Created
March 13, 2010 12:44
-
-
Save ndeuma/331301 to your computer and use it in GitHub Desktop.
Soft HTTP Error handling for Twitter API, using jQuery and JSONP. For cross-domain JSONP requests, you cannot handle other HTTP response codes than 200.
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
this.getJSON = function(url, data, callback) { | |
var api = this; | |
$.getJSON(url, Utils.mergeHashes(data, { suppress_response_codes : true }), | |
function(result) { | |
if (result.error === "Could not authenticate you." || | |
result.error === "This method requires authentication.") | |
$.getJSON(url, data, callback); | |
else if (result.error) { | |
$.event.trigger( "ajaxStop" ); | |
api.errorCallback(result.error); | |
} | |
else | |
callback(result); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment