Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tarasovych's avatar

Correct HTTP status codes for API when exception is thrown

Hello!

Is it ok to return 409 status code when some exception is thrown during user's request process?

For example, when it's impossible to store request data in database.

Thanks in advance!

0 likes
3 replies
s4muel's avatar

depends, if the reason, why the db storing failed is because a duplicate value for example, 409 Conflict is perfectly fine.

422 Unprocessable Entity could be used too, if it makes sense.

but the generic 500 Internal Server Error server side error (that's the point, because 4xx should be used for client side errors) is OK too. you can add a meaningful error message to the response body as well.

1 like
tykus's avatar

It depends on the exception I would say; there are plenty of status codes available to describe the various scenarios that might occur.

1 like

Please or to participate in this conversation.