I have a page that posts something to the server via AJAX. The server side script returns status code 401 if the user is not logged or if the user has no right to post. The problem is, the browser prompts the user with a login dialog and we have no power to suppress that. Is it okay to alter 401 with 500? If no, what appropriate, generic or custom code can I use instead?
1 Answer
A similar question was asked on the Webmasters StackExchange. 401 is used for HTTP authentication, 407 is used for proxy authentication, and both are different from what you are using which is form-based authentication. You could certainly return 500 - Internal Server error when the user is not logged-in, however the post I mentioned recommends using 403 - Forbidden. A list of HTTP status codes and their meaning can be found here.
4 Comments
kazinix
401: "The server understood the request, but is refusing to fulfill it. Authorization will not help and... " It says authorization will not help, what does it mean?
kazinix
It seems like 403 means that whoever the user is, the resource is still forbidden, is that correct?
Nathan Moinvaziri
He states about 'Authorization will not help', that "this should.. be understood.. as referring to.. protocol level authorization mechanisms" aka HTTP authentication. In other words, HTTP authorization will not help, but some other type of authorization such as form-based could. Even though it states that the request SHOULD NOT be repeated, that does not mean a new and different request for re-authorization can't be done.
kazinix
So there are types of authentications... Thanks!