Thursday 26 September 2019

I have one doubt about what http status code should I return in my nodejs api if a request tries to find an user, but its not found in the database.

Hi, today I was writing an test code for my api, there's a route '/confirm-user', that tries to find the username send in the body of the request and returns its userId if one is found.But I started writing the case where the user was not found, because the username was not in the database, so I tested for a response status of 404, not found. The test passed and I proceed to the next. It was then that I noticed that I didn't even set my /confirm-user to the app, so the 404 I got was an generic 404 that returns everytime a wrong request is sent.That let me to think that maybe the correct response was 200, signaling that the request was on a right endpoint, with an message in the body of the response warning the the user was not found in the database. Is this the right approuch in this situation? Is there a best practice guideline for what should be the correct status code response?

Submitted September 27, 2019 at 12:20AM by eliseu_videira

No comments:

Post a Comment