I am trying to handle a particular failure in this JavaScript code:
var script = $wnd.document.createElement('script');
script.setAttribute('src', url);
script.setAttribute('type', 'text/javascript');
When the URL of the script requires the user to be logged in, it returns an HTTP 401 Unauthorized error.
Despite my efforts, I cannot find the appropriate value to catch this error effectively within a try/catch block.
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 expected variable type error has occurred.
URIError: An error when encoding or decoding the URI has occurred (i.e., when calling encodeURI()
).
Is there a specific way to catch the HTTP 401 error, or at least handle the IO error caused by the inability to load the script?
Thank you