I want to catch a specific failure of this JavaScript code:
var script = $wnd.document.createElement('script');
script.setAttribute('src', url);
script.setAttribute('type', 'text/javascript');
When the url where the script resides needs the user to be logged in, and so returns an HTTP 401 Unauthorized error.
None of the values I understand that error (in a try/catch) can take on seem to match very well.
EvalError: An error in the eval() function has occurred.
RangeError: Out of range number value has occurred.
ReferenceError: An illegal reference has occurred.
SyntaxError: A syntax error within code inside the eval() function has occurred. event.
TypeError: An error in the expected variable type has occurred.
URIError: An error when encoding or decoding the URI has occurred (ie: when calling encodeURI()).
Is there any way to catch specifically this 401 error, or at least the class of IO error that would be thrown by not being able to load the script.
Thanks
script.addEventListener('error', function(){
// Didn't load
}, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With