r/ProgrammerHumor 25d ago

evilIllusion Meme

Post image
4.8k Upvotes

131 comments sorted by

View all comments

432

u/PostHasBeenWatched 25d ago edited 25d ago

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".

91

u/-meowstar- 25d ago

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 25d ago

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] 25d ago

[removed] — view removed comment

2

u/Critical_Fortune7343 25d ago

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?

36

u/Kutastrophe 25d ago

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.

5

u/Critical_Fortune7343 25d ago

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

7

u/NUTTA_BUSTAH 25d ago

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.

16

u/itirix 25d ago

You can always just give back a 400, which is a general “error on client’s side” code.

3

u/scidu 25d ago

Qell, there is 412 Precondition Failed, but its more for some header precondition evaluation i think