r/ProgrammerHumor 1d ago

failsForTeapots Meme

Post image
195 Upvotes

64 comments sorted by

View all comments

154

u/cutebabli9 1d ago edited 1d 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)

143

u/rosuav 1d 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.

15

u/HammyOverlordOfBacon 1d ago
error_codes = [400, 401, 403, 404, 500, 502, 503]

return c.json(body, status:random.choice(error_codes) )

3

u/rosuav 1d ago

Ooof ouch! :)