DEV Community

Primož Kerin
Primož Kerin

Posted on

When HTTP 200 OK from API endpoint returns "error"

So this happened a while ago but I will post it here also:

I was posting data to some remote API endpoint and it kept returning HTTP response with code 200 OK. This is normally a good sign, but this was it’s content:


{"error": "not present"}

What is your first guess when you see this response content?

OK, so I thought maybe the API always returns 200 and errors in it’s content. This is not the best practice but I’ve seen it a lot in many APIs. Maybe this was an error description of a case when object is not found in a database, but they could return 404 for example.

However, this was not the case here because I asked them what this "error" meant and why are they returning it with 200 OK.

The answer:

"This is normal behavior and it actually means that no errors are present."

Was your guess correct?

Top comments (1)

Collapse
 
buinauskas profile image
Evaldas Buinauskas

Couldn't really guess.

But in such a case, it'd better to return 204. It's built for exactly this purpose, when request was successful and there's no payload that has to be brought back.