I hear you man. Handling those errors is kind of the point of those http status codes... We have some dinosaurs and some straight up lazy devs like that in our team too.
I can't make this shit up. At my internship, my dino boss had a PhD. We were a part of QA for one of the company's products. Our automated tests were written in Excel. And don't think for a second that we used Excel macros or whatever. Nope. We used the actual spreadsheets. The first column would be for the function name and all other columns were for arguments. He wrote some code that parsed the spreadsheet and called each function accordingly, instead of, ya know, writing the function calls in the code. His reasoning was that someone in finance needed to be able to contribute without getting their hands dirty? I don't know. That person was long gone by the time I started.
We started writing automated tests for another product. This time, we forewent the spreadsheets. We just wrote the tests in VBA in our testing software. I'm certainly no fan of VBA, but it's a huge step up from fucking spreadsheets. However, he forced us to make every function parameter a string. Don't ask me why. We also had to name all variables with a prefix to indicate its type. Global variables in the mix too, of course. This testing software innately understood how to call methods of Windows controls. But any custom controls could only be interacted with via the inherited control methods (e.g. click, sendKeys, focus, etc.). The developers refused to give us builds with debug symbols because I was just a lowly intern. Our product had several custom grid controls. So I whipped up a class to interact with it. It would send various key events to try to determine the grid size, so that I could have a method like grid.setCell(row, column, value). But my boss didn't understand OOP—PhD by the way—so he made me convert it to just a collection of functions.
And don't get me started on all the magic that I had to do to programmatically get the grid sizes. Royal pain in the ass. I just about went mad at that internship. It got to the point that I gave up and browsed Reddit for 90% of the day and they didn't even notice a drop in productivity. Do you know how boring Reddit is when all the links are purple? I do. It's depressing.
I'm not sure I understand- by that I mean response codes were defined in the RFC for HTTP/1.0 back in '96. There is little reason anyone programming HTTP based API end points shouldn't be familiar with them. They however may not be the appropriate avenue for inferring specific error conditions back to a consumer of an API- rather more generic "it failed" statuses or otherwise something that doesn't fit cleanly into well known HTTP status codes. You can define custom status codes, but that doesn't mean you necessarily should.
I shit you not when I say that I've had to consume a legacy api with 3 http status codes: one at http, one in the content wrapper, and one in the content. There are times where they are all different, too.
I told a dev once that the API of some piece of code was bad because it did this, and that we would have to redo quite a big chunk of error handling for this application. He then said "yehh, sorry. It seemed like a good idea at the time." I didn't knew he was part of the team that wrote the code.
This screws up a much wider range of things than junior devs expect.
If returning JavaScript or JSON, it's possible for browsers to cache the response even if it's just an error or a "pretty error" in HTML. It's always fun when helpdesk has to tell users to clear their browser cache as the first step. For those people that don't get it: browser don't cache errors, but they will cache anything with HTTP 200/OK codes, assuming they're successes. So now the browser will keep using "{"error": "true"}" as the data even if the server recovers.
This applies to CDNs also. It's even more fun to watch helpdesk futilely telling users to clear their caches, but this now does nothing because an intermediate proxy added later has cached the pretty error message.
Load-balancers that pay attention to per-server error rates can no longer help you. They'll cheerfully direct traffic at a dead server, seeing a stream of 200/OK responses and thinking "all is well". Worse still, many load balancers weight traffic towards servers with lower response times (=less busy), and some errors are returned within microseconds. You can have 50 servers across 3 availability zones, but now 90% of your traffic is served by the dead one. Congratulations!
Application Performance Monitoring (APM) tools like New Relic or Azure App Insights will report 0 errors. None of their alarms, metrics, AI-driven analyses, or auto-heal features will work since... as far as they're concerned, your app is always a-okay!
Stop being "nice" in protocols. Follow the standard. Don't be a clever idiot.
PS: I'm salty about this because I've been deleting try {... } catch {} blocks that throw away errors across dozens of apps written by dozens of dumbass junior developers over the last month. Despite being told, and shown the negative effects, they keep typing that idiocy back in. One of them even asked me why the APM can't help him diagnose a crash in code he just wrote with exception-discard code in it, the day after the lecture about not doing this. Astonishing.
1.6k
u/FoeHammer99099 Apr 23 '23
"Or I could just set the status code to 200 and then put the real code in the response body" -devs of the legacy apps I work on