I am writing APIs for a backend, where users can register and login etc. In the case that the backend identifies a duplicate username and does not let the user register - would the HTTP error code returned be 409? Because in that case the frontend then gets stuck during the AJAX request since an error is returned. Since I am aware of the error, should I return a 200OK instead?
Asked
Active
Viewed 31 times
0
-
@Bob - you're right, sorry about that - will delete my thread and thanks for the heads up – Luke Galea Aug 06 '19 at 11:42
-
Note you can try to follow [this diagram](https://camo.githubusercontent.com/4e15cccf2a9277dcca2c8824092547dee7058744/68747470733a2f2f7261776769746875622e636f6d2f666f722d4745542f687474702d6465636973696f6e2d6469616772616d2f6d61737465722f6874747064642e706e67) to determine when to return what kind of error code. In the end you should ask yourself though if your code should behave differently when receiving a `400 Bad Request` from a `409 Conflict` or any other 4XX-ish error code – Roman Vottner Aug 06 '19 at 11:47
-
Actually my problem is more related to the AJAX method at the front-end. From my backend, I am returning an HTTP code 409 and message string containing "Username duplicate". However in the AJAX method if a 409 code is detected, the message field is not read. Perhaps I should use .fail method instead? – Luke Galea Aug 06 '19 at 11:49
-
1This is more related to AJAX then to the actual HTTP method then IMO – Roman Vottner Aug 06 '19 at 11:52