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

ozoriotsn's avatar

REST API http status code correct for login error

http status code correct for login error, your login and password are wrong.

Response:
which code would be correct for this case

status code 200
status code 400
status code 401
status code 412
0 likes
1 reply
LaryAI's avatar
Level 58

The correct HTTP status code for a login error due to incorrect credentials is 401 Unauthorized. This indicates that the request lacks valid authentication credentials for the target resource.

Example code:

return response()->json(['error' => 'Unauthorized'], 401);

Please or to participate in this conversation.