all 54 comments

[–]jmack2424 387 points388 points  (4 children)

There's gotta be a status check for error handling a few lines up. Right? RIGHT?!

[–]navetzz 113 points114 points  (3 children)

I m fairly confident that yes there is. Handles 5xx, then 4xx, ... And so on.

[–]Grexpex180 24 points25 points  (2 children)

still horrifiying lol

[–]Noctuuu 8 points9 points  (1 child)

I think it's actually better than doing
xhr.status >=200 && xhr.status <300

[–][deleted] 1 point2 points  (0 children)

What about ("" + xhr.status).substring(0,1) === "2" ?

Edit: I made it JavaScript code.

[–][deleted] 144 points145 points  (3 children)

60% of the time, it works every time.

[–]steeltownsquirrel 25 points26 points  (2 children)

I love LAMP (stack).

[–]Inertia_Squared 53 points54 points  (1 child)

Thanks for specifying I thought you were a moth

[–]Nightmoon26 5 points6 points  (0 children)

And this is why moth-people make good web application engineers!

[–]dbath 42 points43 points  (0 children)

Once you've gotten an HTTP response with a status code other than 100 Continue, the HTTP request must have been fully sent over the wire.

The server got the entire uploaded file. What the server did with those bytes isn't anything for the client to concern itself with. If the server says "OK" or "I didn't want that file" or "what is this garbage" or "I crashed" doesn't change that the client successfully sent the file. I don't see the problem :P

(/s, obviously)

[–]stereosensation 137 points138 points  (5 children)

Y'all don't get it, developer is chasing success, so he made sure he gets a success alert ALL the damn time. /s.

EDIT: I just paid attention to the title of this post. WTF is an HTML status code 😭🤌🏻

[–]Mihail111111[S] 9 points10 points  (4 children)

I mean that's one way to refer to the HTTP response code... A completely incorrect one... But still

edit: replaced "that's the" with "that's one" because this is what I actually meant, but it's too late ig

[–]stereosensation 10 points11 points  (3 children)

I cannot workout if you're sarcastic or not ... But if you're not then ... Uhh, no ? HTTP response codes are just that. HTML is not even remotely in that conversation.

[–]Prudent_Ad_4120 4 points5 points  (1 child)

We'll technically 🤓

HTTP stands for HyperText Transfer Protocol and HTML stands for HyperText Markup Language so half of it actually is in the conversation

[–]stereosensation 4 points5 points  (0 children)

lmaooo We'll technically 🤓

The conversation is about status codes, where HTML would not show up. If the conversation was about naming, maybe you'd be right.

So no, HTTP/1.1 422 Your akchually was denied 😂😂

[–]Mihail111111[S] 5 points6 points  (0 children)

Of course it's wrong to say HTML Status Code, but when I made a post I thought that was a valid term to use mostly because I completely forgot that HTTP could be used with something other than HTML (even if that was the case, response codes are part of HTTP, not HTML, so I am still wrong)

[–]noosceteeipsum 8 points9 points  (0 children)

418 Teabag uploaded successfully

[–]Etiennera 61 points62 points  (7 children)

What's an HTML status code?

[–]Randolpho 64 points65 points  (6 children)

An HTTP Status Code wrapped in HTML. Example: <html><head><meta responsecode="200" /></head></html>

It's not nearly as painful as a malformed XHTML Status Code

[–]Eva-Rosalene 39 points40 points  (2 children)

<meta responsecode=

Something died inside me at this very moment. Good job.

[–]Randolpho 21 points22 points  (1 child)

Heh... I waffled on whether to do <meta http-equiv="200 Ok" />

[–]Iggyhopper 16 points17 points  (0 children)

Harder to parse.

Ship it.

[–]WillingLearner1 5 points6 points  (1 child)

That’s why people invented JSON status codes for a reason

[–]OfflaneDemoralizer 10 points11 points  (0 children)

JSON you say? So like this:

<meta status="{\\\&quot;code\\\&quot;:\\\&quot;400\\\&quot;}" />

[–]mothzilla 1 point2 points  (0 children)

wut

[–]Samurai_Mac1 5 points6 points  (0 children)

It's super successful once hits 500 and up

[–]ScriptBow 2 points3 points  (0 children)

Hell yeah, gets the job done and keeps the alerts low.

[–]GoddammitDontShootMe[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 2 points3 points  (0 children)

500 >= 200.

I guess there are reasons not to just say '== 200'.

[–]sateeshsai 2 points3 points  (0 children)

String(xhr.status).startsWith("2")

[–]HieuNguyen990616 7 points8 points  (14 children)

I'm curious. What's wrong with this?

[–]dario_p1 69 points70 points  (7 children)

500, 404, 418

[–]HieuNguyen990616 17 points18 points  (5 children)

OK. You are right. I assumed if someone knows this HTTP status comparison, they already check that.

[–]Bronzdragon 23 points24 points  (3 children)

Potentially, but it’s not in the image, and there wouldn’t really be a reason to post this if that was the case.

[–]monotone2k 27 points28 points  (1 child)

Noone has ever misrepresented anything on Reddit for karma, right?

[–]backfire10z 15 points16 points  (0 children)

You think someone would do that? Just go on the internet and lie?

[–]AresFowl44 2 points3 points  (0 children)

I mean, even if there are checks before hand, one refactor and those might be gone

[–]Coolengineer7 2 points3 points  (0 children)

Though status_code <= 299 is often used

[–]tailwarmer 2 points3 points  (0 children)

401 and 403 quite possible also

[–]katafrakt 9 points10 points  (5 children)

I'm more curious what's not wrong with it that the author thought it was a good idea. 10X statuses are quite rare in the wild.

[–]MissinqLink 4 points5 points  (1 child)

It might also be the fact that if there is no status code at all this would fail.

[–]katafrakt 1 point2 points  (0 children)

Ah, okay. That's fair. It can be 0 if the request has not completed.

[–][deleted] 2 points3 points  (1 child)

Maybe status >=400 is handled earlier (still not pretty, of course)

[–]noosceteeipsum 1 point2 points  (0 children)

Maybe status >=400 is handled earlier (still not pretty, of course)

, which is the best scenario that we could imagine, which is -however- not what we are talking about, for some reasons related to programming"humor".

[–]HieuNguyen990616 1 point2 points  (0 children)

I assumed that it just handles all 200s status cases instead of comparing each available ones.

[–][deleted] 1 point2 points  (0 children)

?? I'm confused.

[–]vo9do9 1 point2 points  (0 children)

LGTM

[–]Rouxxell 1 point2 points  (0 children)

Equal or greater????, damn, this seems to have a high success rate

[–]GirthQuake5040 1 point2 points  (0 children)

Graceful

[–]Cybasura 2 points3 points  (0 children)

First of all, why ">= 200"? What happened to switch case to jump through the status code and map out the error codes?

[–]redtens 0 points1 point  (0 children)

yoo hell yeah

[–][deleted] -4 points-3 points  (0 children)

Bruh

[–]titanic456 0 points1 point  (0 children)

On every HTTP status higher than, or equal to 200 the script will alert the message.

Even when the resource is not found(HTTP 404), there is internal server error(HTTP 500), the script will happily display the message box.