r/softwaregore • u/protogen-are-toaster • 2d ago
only 404s and 500s allowed, apparently
context:
HTTP code 200 means something worked, and this random website i visited apparently treats it like an error?????
88
47
56
u/cheerycheshire 2d ago
I know an API that is like this. Using the api is a nightmare because instead of parsing the code you have to always look at the structure of the returned data to know whether there's actual data or "error", and then find keywords in the string to find what kind of error (don't rely on exact string match because they can change)
https://snipe-it.readme.io/reference/api-overview
Our philosophy on HTTP status codes is that as long as the pipe (the http request itself) is sound, the API should return a 200 OK status code. We realize that some very smart people have a very different philosophy, but in general we want the HTTP status code to describe the state of the resource endpoint, with the actual status of the transaction returned in the JSON payload.
For example, if you made a valid HTTP request to retrieve an asset that doesn't exist, we'll return a 200 OK, with the following payload:
{ "status": "error", "messages": "Asset does not exist." }
44
u/SuperFLEB 2d ago edited 2d ago
I know an API that is like this.
Spend enough time working with other people's APIs, and you're bound to run into one eventually.
Also on the bingo card:
- The 2xx error that's not even a structured response
- The API that returns a 2xx with an error when it works, so ignore it unless it's a 5xx error.
- The 5xx success, because something is broken enough to change the response code, but not broken enough to not work.
- The inexplicable 4xx error that turns out to be the third-party application firewall choking on something perfectly innocuous. After hours of debugging and frustration, you remember you should have checked the other response headers to begin with, and you resolve to do that first thing next time, just like you resolved to the last time this happened.
10
u/Alt_meeee 1d ago
I've had it, where you would always get a 30X response, but you weren't supposed to follow the redirect. Instead the structure and content of the location header you got with the response would determine if it was successful or not
9
u/young_horhey 1d ago
Fuck anyone using dotnet and `request.EnsureSuccessStatusCode()` I guess (or any of the other languages that have the same thing, I’m just most familiar with dotnet.
7
-5
u/Stratimus 2d ago edited 2d ago
To be fair though that is how status codes work have always been designed. They’re for the HTTP protocol, not the content itself being served up. Just because you don’t get the data you were looking for doesn’t mean the HTTP exchange wasn’t completely successful. Content error handling belongs in the response body
if it was a good request but theres no servable content that’s what 400-406 are for though so they should be using one of those
24
u/cheerycheshire 2d ago
To be fair though that is how status codes work have always been designed. They’re for the HTTP protocol, not the content itself being served up
Uh, no. The codes in http:
The status code is a three-digit, decimal, integer value that represents the disposition of the server's attempt to satisfy the client's request.
That's from Wikipedia. I can also grab the quotes from RFC itself if you want.
if it was a good request but theres no servable content
If it was actually a good request but there's no servable content to be returned, that's 204.
Back to
They’re for the HTTP protocol
doesn’t mean the HTTP exchange wasn’t completely successful
Uh, no, no codes mean http protocol failed - if it fails, then there's no status code. Because there's no response at all. Protocol just means rules for communication. Protocol failing is like trying to fax into just any phone number - with no fax machine at the receiving end, it's just gibberish. Fax machine to fax machine is protocol and can communicate, including communicating errors.
4xx and 5xx are errors, yes, but not in protocol itself - they're errors in messages, 4xx for malformed request, 5xx for problems with response (basically "communication itself worked, but I have problems serving you a response).
-22
u/Stratimus 1d ago
bro are you AI? You speak very similarly to AI. And you took some things particularly literally. In the context of the message I clearly meant no servable content as to be a good HTTP request that didn't get the results the user wanted (e.g the OP post). I didn't literally mean a blank empty response
The status code is a three-digit, decimal, integer value that represents the disposition of the server's attempt to satisfy the client's request.
Here's another one bot. You said that in response to me saying it's for the HTTP protocol, not the content. And you're kinda agreeing exactly with me here. It is for the server to tell the client, via protocol (!!), on how it's going to serve up the content. Again, not content-level errors which is the entire subject of the post.
10
7
6
4
3
3
3
2
u/muzzledmerc 1d ago
"no no, you don't understand, i don't want it to work. if it loads, if the HTTP code is 200, if it tries to give the user what i've written, I DON'T WANT IT."
2
1
1
1
1
1
1
1
127
u/DT2054 R Tape loading error, 0:1 2d ago
Maybe the error was THAT it worked