Implement 'error' callback for Dynamically loaded javascript file
<p>I am loading javascript dynamically and accessing its variable. I checked the <strong>second</strong> answer from this <a href="https://stackoverflow.com/questions/2736943/cant-access-variables-from-dynamically-loaded-javascript">question</a> and the following code works beautifully. </p>

<pre><code>include = function (url, fn) {
    var e = document.createElement("script");
    e.onload = fn;
    e.src = url;
    e.async=true;
    document.getElementsByTagName("head")[0].appendChild(e);
};

include("test.js",function(){
    console.log(foo);
});
</code></pre>

<p><strong>QUESTION:</strong> I want to have a <code>onFailure</code> callback function as well that allows me to process code in case </p>

<ul>
<li>The internet is down.</li>
<li>The filename is not accessible (eg: incorrect path)</li>
</ul>

<p>Will appreciate if someone can guide me to the right direction.
Thanks</p>