Search code examples
responsehttp-status-codes

Status code for a response that work's but doesn't have a answer


I'm current building a API that can return a determinated city based on it name. My code it's working, the problem that i'm facing is the correct status code to use on a request, that fulfilled itself, but doesn't has a answer, because the city wasn't found.

Which status code should i use in this case? I tried use 204 NO-CONTENT, but then the response doesn't have a body and my custom exception for city-not-found became useless.


Solution

  • The HTTP 204 No-Content code is a success status response code, indicates that a request has succeeded. In this case you can try 404 Not-Found which u can catch and use your custom exception.