I'm building a simple http server in nodejs that validates the outgoing json. If the validation fails, what would be the correct status code / error message to send to the client?
Asked
Active
Viewed 562 times
2
-
@CertainPerformance no, if the json outputted by the server. In case of client json would be 400 / 422, right? – brielov Dec 23 '20 at 16:36
-
500 - Internal Server Error. If the server generated an invalid response to a valid request, its clearly an internal error, isn't it? – tkausl Dec 23 '20 at 16:37
-
@tkausl Thanks, that's what I have right now, I wasn't sure though. – brielov Dec 23 '20 at 16:38
2 Answers
0
Since the error occurs on the server, the error should be in the 500s.
There doesn't appear to be any error message corresponding to this problem in particular, so you can use the generic one indicating that there was some problem on the server: Error 500 Internal Server Error. Logic performed on the server failed to fulfill expectations.

CertainPerformance
- 356,069
- 52
- 309
- 320
-1
The common status codes are:
4xx means client errors
- 400 bad request
- 401 unauthorized
- 403 Forbidden
- 404 Not found
- 405 method not allowed
2xx means HTTP code status
- 200 OKs, this is for the update or get resource successfully
- 201, means that any source was created
- 204, means that request doest have a useful load, but we have used it when are updating
5xx means server errors
- 500 Internal server error
- 501 Not implemented
- 502 bad gateway
- 503 services unavailable
There are more. But these are perhaps the most common

reivaj96
- 1