Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a snipped that detectes non-network related errors from an xhr-get request and outputs some information about it in the console.</p> <p>There is an extra isEvalError() function that goes through all eval-error types... which I am not really proud of. A nicer way could be by getting the parent object of the errorMessage sub-classes. I think you can ditch isEvalError() generally, because there shouldn´t be any other error possible in this block.</p> <pre><code>function isEvalError(errorMessage){ return errorMessage.name == "RangeError" || errorMessage.name == "ReferenceError" || errorMessage.name == "SyntaxError" || errorMessage.name == "URIError" || errorMessage.name == "TypeError"; } var foo = dojo.xhrGet({ url: 'stacko.js', handleAs: "javascript", load: function(returnValue) { console.log("load: "+returnValue); }, error: function(errorMessage,ioargs) { //request worked fine, this must be a non-network related error if(ioargs.xhr.readyState == 4 &amp;&amp; ioargs.xhr.status == 200) { if(isEvalError(errorMessage)){ //show eval-error, url request &amp; the JS code that causes the exception //eval-error types: RangeError,ReferenceError,SyntaxError, URIError, TypeError console.error(errorMessage.name+" in JS Code detected: (url: "+ioargs.url+")") console.error("Error Message: "+ errorMessage); console.error(ioargs.xhr.responseText); } //a little reflection - if u want to know who triggered this error //(although in this case the output is not very helpful ) console.error("Error triggered by: "+arguments.callee.caller.toString()); //last but not least log the error &amp; the xhr-request object for more information console.error("XHR Object:"); console.error(ioargs); console.error("Error Object:"); console.error(errorMessage); } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload