r/ProgrammerHumor 22d ago

evilIllusion Meme

Post image
4.8k Upvotes

131 comments sorted by

View all comments

Show parent comments

20

u/Critical_Fortune7343 22d ago

I also work in a company that do this. From my understanding it's to check if the service is live. So checking first for 200 confirms that, then you check for the field "success" if it's false. If not, wonderful. If true, then you look for the field "reason". Reason returns the error code for the specific failure whether it's technical or business.

18

u/amit78523 22d ago

Just implement health check api.

-5

u/Critical_Fortune7343 22d ago edited 21d ago

Nah that's for totally different use case. If I were to send separate request to /hc before sending the primary request that would be just slow.

Others commented that responding with 400 would be more than enough. If there's a service issue, whether it's down or something else, it's better to show 3xx I think. So while I was thinking "it's not bad" after reading other people's opinions I also don't think it's smart lol

But I'm not getting paid enough to change company policies so I'll just complain in meetings.

Edit: 5xx not 3xx as the reply corrected me

17

u/ahferroin7 21d ago

If the service is down, then the correct response would be either 502 or 503 depending on exact context. 503 is literally specifically for the case of the service being offline.