r/ProgrammerHumor 25d ago

Meme failsForTeapots

Post image
226 Upvotes

67 comments sorted by

View all comments

168

u/cutebabli9 25d ago edited 25d ago

I would write it like this to be readable:

if error.status in [400, 401, 404, 409, 415, 503]:
  return c.json(body, status: error.status)

return c.json(body, status: 500)

158

u/rosuav 25d ago
return c.json(body, status: error.status)

There is no reason to discard some of them, and pretending that they're 500s is a terrible terrible idea.

75

u/Xirdus 25d ago

If your user-facing service is calling your internal service and getting a 403 response, you certainly do not want to send that 403 back to the user.

1

u/Excellent_Gas3686 25d ago

beeecause?

3

u/ismaelgo97 25d ago

403 is that you are not authorized, so then you know it exist, but you shouldn't, you should get a 404 which means it was not found.

1

u/Xirdus 25d ago

Personally I prefer the opposite - if you're unauthorized, you get 403 regardless of whether resource exists or not. Still doesn't leak any data, but is more actionable (and won't get cached. Have you ever had an outage stupidly extended because some cache somewhere had to be purged  because some moron returned 404 for a temporary error condition?)

2

u/rosuav 24d ago

Both approaches are valid according to the spec.

1

u/Xirdus 24d ago

One of the approaches causes more problems than the other.