Question

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.)

Was it helpful?

Solution

Look into suppress_response_codes

It is explained about 1/4 way down the page here: https://dev.twitter.com/docs/things-every-developer-should-know

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top