TankorSmash
TankorSmash

Reputation: 12747

How to catch Chrome's net:: exceptions using jQuery.get?

More specifically, I'm looking to catch net::ERR_CONTENT_LENGTH_MISMATCH, but in general how does one catch errors like this?

$.get(example_valid_url).error(function(req, status, e){}) doesn't have any of the information, and the status code of the response is 0.

Wrapping the code in a try...catch doesn't help either, as the error isn't caught.

Upvotes: 2

Views: 533

Answers (1)

using the $.get example is probably misleading (because if that was the problem, there are other ways to do url validation before allowing a xmlhttprequest through).

net:: errors cannot be try/caught, as they are protocol violations, rather than in-protocol responses that just aren't "http:200 OK". If you get a net:: error, it means the code you're using is trying to do things (or is initiating things) that would break the browser if allowed through, not just the script you're currently running.

Upvotes: 2

Related Questions