Home > Net >  Which is a correct HTTP status code for "Error creating resource"?
Which is a correct HTTP status code for "Error creating resource"?

Time:11-12

I'm developing an application with authentication, and i need to provide a appropriate status code if there is any error when registering an user, for example a database-related error.

I've been researching but i haven't found an appropriate status code.

CodePudding user response:

The purpose of all HTTP errors is to communicate the operation failed. To pick the right HTTP error, you need to know why it failed.

"database-related error" sounds like a server-side bug or problem, so this is likely just a 500.

CodePudding user response:

You should use the 403 error code

https://en.wikipedia.org/wiki/HTTP_403

From the documentation :

Error 403: "The server understood the request, but is refusing to authorize it." (RFC 7231)[1]

This is the most fitting status code regarding the purpose you want.

  • Related