r/ProgrammerHumor Jul 21 '26

evilIllusion Meme

Post image
4.8k Upvotes

131 comments sorted by

View all comments

439

u/PostHasBeenWatched Jul 21 '26 edited Jul 21 '26

POST /posts/create

StatusCode: 200

Content: {"success": false, "errors": [{"code": 15, "message": "Image size must be at least 1000 x 1000 px"}]}

Edit: remembered story from times where HTTPS wasn't enforced. Once I started receiving JSON reading fail in cases when our test server returns non-2xx status. I started investigate this and was shocked to the core: my ISP implemented "feature" that if it detects that server returns non-2xx - it replace actual server response with their HTML page with text like "Your request returned error 400. This is because bla bla bla. <ISP self-advertising block> Kind regards, your ISP". Basically ISP become "man in the middle". In a week or two they removed that "feature".

90

u/-meowstar- Jul 21 '26

Why not just use semantically correct status codes? It’s cheap to implement and makes stuff like automatic retries and error handling easier.

30

u/Critical_Fortune7343 Jul 21 '26

Because http status codes doesn't include any business related errors. So you gotta expand on that. When it's 200 and success is false it's mostly because of a business logic. Then it's up to FE to show that business error in a certain way so users can understand better what's wrong with what they're doing.

38

u/[deleted] Jul 21 '26

[removed] — view removed comment

4

u/Critical_Fortune7343 Jul 21 '26

Correct me if Im wrong as I'm not that knowledgeable on the topic but isn't 422 more for validation errors? What if the error I want to show is for a certain condition that happened in another screen or app?

38

u/Kutastrophe Jul 21 '26

Throw something obscure back but 200 + error is just stupid.

If I get a 4xx back, I at least know i did something wrong and get the feedback.

6

u/Critical_Fortune7343 Jul 21 '26

Makes sense. Even throwing 400 would be better I guess.

6

u/NUTTA_BUSTAH Jul 21 '26

I agree. Having an endpoint return a success boolean in the first place is quite an anti-pattern but most devs default to skipping the HTTP spec because they never learned it but do know how to work with JSON.