Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What HTTP error code to return for name already taken?

I'm doing an AJAX call to set the username. If the username is already taken what HTTP code should I return?

like image 661
Ryan Avatar asked Sep 29 '12 23:09

Ryan


People also ask

What is HTTP error code1?

The server does not support, or refuses to support, the HTTP protocol version that was used in the request message. The server is indicating that it is unable or unwilling to complete the request using the same major version as the client, as described in section 3.1, other than with this error message.

What HTTP status code for user already exists?

A 403 - Already Exists error indicates that it is not possible to create a resource with the given definition because another resource already exists with the same attributes. Such errors always correspond with a 403 HTTP status code.

What is the HTTP status code for duplicate record?

409 Conflict - Client attempting to create a duplicate record, which is not allowed. 410 Gone - The requested resource has been deleted. 411 Length Required - The server will not accept the request without the Content-Length Header.

What are HTTP 200 errors?

The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default. The meaning of a success depends on the HTTP request method: GET : The resource has been fetched and is transmitted in the message body.


2 Answers

You can use 409 Conflict.

Indicates that the request could not be processed because of conflict in the current state.

like image 189
Navrattan Yadav Avatar answered Sep 30 '22 22:09

Navrattan Yadav


I would choose 422 Unprocessable Entity . Lot's of rails developers use this for all validation errors.

And yes, it is totally appropriate to evaluate the error status and render the error message with javascript. This is especially useful, if you are using the same actions for an API. Then your ajax requests are accessing the same API that you would expose to other developers.

like image 20
digidigo Avatar answered Sep 30 '22 22:09

digidigo