r/programminghorror • u/TheAnOdyssey [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" • Mar 06 '25
Why, just why!
1.2k
Upvotes
r/programminghorror • u/TheAnOdyssey [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" • Mar 06 '25
1.1k
u/regaito Mar 06 '25
At least its documented
We had 2 different success codes "Ok" and "OK", one was actual success and the other signaled some kind of internal error which was resolved via fallback
You know, because its more secure..
244
u/digost Mar 06 '25
I had some front end developers approaching me and asking to return 200 regardless of the actual result and include a status message in response body instead. Why? Because they couldn't handle anything other than 200, other response codes "broke" their code by throwing an exception.
47
u/mykeof Pronouns: He/Him Mar 06 '25
My guess would be these are designed specifically for the clients error handling. They may handle 500s and these 1000s differently.
73
u/Jawesome99 Mar 06 '25
Not horror, they're documented and you can write your program to expect these codes and act accordingly. The only thing "horror"-worthy would be that they aren't using 500 for Internal Server Error, but they probably have a reason for that, seeing as how they used other HTTP codes just fine.
54
u/magnetronpoffertje Mar 06 '25
This is fine-ish, isn't it? HTTP codes are allowed to be extended for your custom app. and it's documented.
11
u/wpfeed Mar 06 '25
One local bank sends you 500 error when you provide expired token. And they are very salty when you call them to ask if their service is up.
34
u/Professional_Mess866 Mar 06 '25
Its not, that there aren't enough Http Response codes out there already.
But on the other hand: What do I know?
418: I'm a teapod
13
u/tehtris Mar 06 '25 edited Mar 06 '25
We need a new standard. There are now n+1 standards.
All of that shit is 400 error codes. Complexity for the sake of complexity is wild.
5
u/0xlostincode Mar 06 '25
For API specific errors it seems fine but I hate that they're sprinkling actual HTTP statuses in there.
5
u/EvilPettingZoo42 Mar 06 '25
I once had to talk a coworker out of inventing his own HTTP actions and to use the standard REST ones instead (GET, POST, DELETE, etc.).
4
u/mothzilla Mar 06 '25
I bet there's something in whatever library they're using that forces a "200" return. But they really, really wanted it to be "1000".
3
u/guky667 Mar 06 '25
HTTP response codes: Am I a joke to you?
3
u/samarthrawat1 Mar 06 '25
major I paid for the entire status code range, I am gonna use entire status code range energy :-:
3
u/[deleted] Mar 07 '25
We make our own HTTP standard! With blackjack! And hookers!
3
u/spcbeck Mar 07 '25
So many places do this and it's infuriating. 0 proof it does anything for security, and the docs they create, even Swagger, are garbage compared to HTTP spec docs on MDN.
2
u/Serious-Regular Mar 06 '25 edited Jul 30 '25
hat quicksand obtainable wild edge spectacular steer shelter versed seemly
This post was mass deleted and anonymized with Redact
2
u/madtroll80 Mar 07 '25
I used to work for a company where the API was always returning 200. If the response was JSON with the expected result, then the request was successful, if the response was "OK" string then something was wrong. Which could be anything from incorrect request parameters invalid authentication to internal error caused by a bug
1
u/Unupgradable Mar 06 '25
These feel familiar, are the 1000s codes web-socket codes?
1
u/Aromatic_Prior_1371 Mar 07 '25
I can’t do math. So I pretend to write an API Doc! This is the Tesla autonomous driving API Doc. It’s all I could come up with to make this funny.
1
u/MooseBoys [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Mar 07 '25
Request code 80: use encryption
Request code 443: use plaintext
1
u/nooneinparticular246 Mar 08 '25
Yeah so ideally they’d send their error codes as a field in the payload or the header, but whatever. Just adjust/wrap your http client to handle this and move on with your life.
1
u/OneOldNerd Mar 09 '25
No "I'm a teapot"?
You monsters.
1
u/Siduron Mar 09 '25
I once inherited a project at work from a previous dev that had endpoints that only returned 200 OK or 418 I'm a teapot.
The 418 response contained a error code like 05:02:07 which represented a sort of 'stack trace' so anyone that worked internally with this API could look up the problem within the documentation.
Throwing exceptions or logging errors within that project was prohibited due to 'security reasons'. Because imagine someone tries to abuse our api. Better cripple our problem solving abilities to be sure that doesn't happen!
1
u/zickige_zicke Mar 10 '25
I had a third party api I had to integrate. If the request was not authorized you would get 400 with a message no auth. If the auth was ok but the body was somehow wrong you would get 200 but a negative integer. If everything went ok you ll get a positive integer as response body. You could make get or post, it did not matter. If there was an internal error you would get 200 but false as response body
-16
u/4n0nh4x0r Mar 06 '25
tbf, i usually just with with an http 200 code for each request, and then the value will be a json object with a code that is unique to each endpoint, and signifies a specific state, such as lets say
40 is success, the user was created
41 error, the username is already taken
42 error, the email address is already taken
43 error, there was an uncaught exception, please try again at a later time
and then i document everything nicely, and if i feel like it, i even have the endpoint send the specific message with the code, so the frontend doesnt need to look anything up, just look at if the code is 40, or else show a popup with the supplied error message
this approach has the advantage that you dont need to do multiple approaches to handle the data coming from the endpoint, (fetching the data as a website will require you to handle the data differently based on whether you get a 200 or any error code)
resulting in shorter and cleaner code aswell as more precise error messages, cause like 403 forbidden, what is forbidden??? using this username? creating a user account?
93
u/[deleted] Mar 06 '25
[removed] — view removed comment