Skip to content

Instantly share code, notes, and snippets.

@ndeuma
Created March 13, 2010 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndeuma/331301 to your computer and use it in GitHub Desktop.
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.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