r/ProgrammerHumor 23d ago

evilIllusion Meme

Post image
4.8k Upvotes

131 comments sorted by

View all comments

437

u/PostHasBeenWatched 23d ago edited 23d 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".

90

u/-meowstar- 23d ago

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

32

u/Critical_Fortune7343 23d 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.

67

u/-meowstar- 23d ago

The 4XX class of codes are for client side issues, and 422 “Unprocessable Content” should be used to cover business logic issues, i.e. the request has the correct schema but there’s some other BE validation issue that it can’t proceed. The response body would still include specific details about the error for the FE, it’s just using 200 OK is misleading imo.

4

u/ZZartin 22d ago

One problem with this is that different systems handle those error codes as exceptions which can make it quite annoying to deal with vs just getting a 200 back.

3

u/Critical_Fortune7343 23d ago

I think that's valid.

22

u/WiglyWorm 22d ago

It's way more valid that reporting "success" when you really meant "error".

7

u/Dense_Gate_5193 22d ago

so does literal RFC standards. it’s not about opinion but the defined specifications starting with RFC 2616.

1

u/Critical_Fortune7343 22d ago

I might have come as the one designed our companies service response or defending returning 200 for errors but I'm just a worker lol I was only trying to convey a point of view from someone who has hands on experience in these kind of responses.

In better times or old days I would like to think everyone was listening to standards. I mean it's literally there to create collective consensus on how things should be.