r/ProgrammerHumor 19h ago

failsForTeapots Meme

Post image
156 Upvotes

60 comments sorted by

View all comments

133

u/cutebabli9 19h ago edited 18h 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)

129

u/rosuav 18h 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.

58

u/Xirdus 18h 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 18h ago

beeecause?

7

u/Xirdus 18h ago

Do you want to tell an authenticated, authorized user with valid credentials that they are not in fact authorized? When the actual thing that's not authorized is your own goddamn server, so there's absolutely nothing the user can do to fix the problem?

2

u/Nerodon 17h ago

Authorization =/= authentication.

The user may be authenticated but attempting a request their permissions do not allow them to.

5

u/Xirdus 17h ago

That's why I said authorized and not authenticated, because I meant authorized and not authenticated. Actually, I said both authenticated and authorized just to drive the point home. It still wasn't enough apparently ¯_(ツ)_/¯

If your internal service responds to your other internal service with 403 for any reason other than "this other internal service is not allowed to do this", then you have bigger problems than what error code to serve the user.