views:

425

answers:

1

I'm using jQuery's ajax methods to interact with the Twitter REST API.

Their API is a bit annoying, in that some actions will return a 401 HTTP status code. In that case, I just want it to fail, instead of displaying a login box.

I've tried just providing an incorrect user:pass pair in the URL, in case that might suppress the dialog and just get me an error response, but that failed to help.

This question asked exactly the same question, but the answer instead worked out how to not trigger the 401 in the first place.

(In particular this is annoying because it's a bug on their part that's requesting authentication -- the users/show method isn't supposed to be asking for it in the first place.)

+2  A: 

Look into suppress_response_codes

It is explained about 1/4 way down the page here: http://apiwiki.twitter.com/Things-Every-Developer-Should-Know#5Parametershavecertainexpectations

From the Twitter documentation (incase it is moved again):

suppress_response_codes: If this parameter is present, all responses will be returned with a 200 OK status code - even errors. This parameter exists to accommodate Flash and JavaScript applications running in browsers that intercept all non-200 responses. If used, it's then the job of the client to determine error states by parsing the response body. Use with caution, as those error messages may change.

epascarello
Thank you, I overlooked that. I'd still like some general way to avoid the issue entirely, but that definitely solves my problem.
David
twitter has moved their documentation. please include the gist of the solution in the stackoverflow answer.
landon9720
@landon9720 I have updated the url in the answer.
apphacker