You are viewing a single thread.
View all comments
4 points

Honestly makes perfect sense.

  1. Message received and successfully parsed.
  2. An error occured while processing request. Ideally they would have a message in the response saying what went wrong if it is relevant for the user.

The problem with only reacting with 500 Internal Server Error is that the user will never improve their input data, if they can do something about it. Responding with 404 is just mean as they wont know if the endpoint is not found or the database couldn’t find any data. Differentiating the communication from the processing is i.m.o the best way to do it.

permalink
report
reply
45 points

That’s not what HTTP errors are about, HTTP is a high level application protocol and its errors are supposed to be around access to resources, the underlying QUIC or TCP will handle most lower level networking nuances.

Also, 5xx errors are not about incorrect inputs, that’s 4xx.

permalink
report
parent
reply
45 points

permalink
report
parent
reply
27 points

…HTTP is a high level application protocol and its errors are supposed to be around access to resources…

I’ve had fellow developers fight me on this point, in much the same way as your parent post.

“If you return a 404 for a record not found, how will I know I have the right endpoint?”

You’ll know you have the right endpoint because I advertised it—in Open API, in docs, etc.

“But, if /users/123 returns a 404, does that mean that the endpoint can’t be found or the record can’t be found?”

Doesn’t matter. That resource doesn’t exist. So, act appropriately.

permalink
report
parent
reply
9 points

Standardize a response body across your APIs that specifies the cause of the non-2xx response. Have an enum per API/service for causes. Include them in the API doc.

If anyone still doesn’t get it, quietly dispose of them at your friend’s pig farm.

permalink
report
parent
reply
4 points

It’s not like you can’t return a body with the 404 that specifies that the user itself is not found versus the ending being wrong.

permalink
report
parent
reply
3 points

And it’s not even always a simple case of “that resource doesn’t exist”. A 404 could also mean that the resource does exist but the current authenticated user doesn’t have the correct permissions to access it, so it’s more like “as far as you know that resource doesn’t exist”. Some people might argue that 403 should be used for that, but then you’re telling potential bad actors that maybe shouldn’t even have access to your documentation that they have indeed found a valid endpoint.

permalink
report
parent
reply
1 point

The parser in most APIs will automatically handle parsing responses for 400 errors, but if the logic fails due to data being wrong, what do you respond with? E.g you send a valid SSN but the database could not find the person, or you send a valid email, but bo such email was found.

permalink
report
parent
reply
15 points

You can send 4xx errors yourself too. If the client needs to change something about the request, that’s a 4xx, like 400 Bad Request. If the server has an error and it’s not the client’s fault, that’s a 5xx like 502 Bad Gateway.

The wikipedia listing of all HTTP codes is quite helpful. People also forget you can send a custom response body with a 4xx or 5xx error. So you can still make a custom JSON error message.

permalink
report
parent
reply
2 points

That’s still a 4xx situation.

permalink
report
parent
reply
15 points

Except of course that http has a myriad of response codes that are more useful than a 200 with an error body. This was a serious mistake of GraphQL imo

permalink
report
parent
reply
7 points
*

What’s wrong with graphql over a web socket? Graphql doesn’t necessitate http or any other transport method, it can be done via pigeons. Graphql has zero control over how http works when you use graphql over http, it doesn’t force implementors to use http at all

permalink
report
parent
reply
5 points

Aww a whole new generation of devs get to make the same mistakes SOAP made. Makes me feel all fuzzy inside.

permalink
report
parent
reply
1 point

Meanwhile, in the real world…

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 9.7K

    Monthly active users

  • 1.3K

    Posts

  • 47K

    Comments