Skip to content

Commit

Permalink
release 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
camsong committed Jun 10, 2017
1 parent 5ee6858 commit 7fb44c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.1.1 / 2017-6-10
==================
* Fix script error when script request error, thanks to @wheatma

1.1.0 / 2017-6-7
==================
* Handle <script> error event, thanks to @michaelvial
Expand Down
21 changes: 12 additions & 9 deletions build/fetch-jsonp.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000);
}

// Known issue: Will throw 'Uncaught ReferenceError: callback_*** is not defined'
// error if request timeout
function clearFunction(functionName) {
// IE8 throws an exception when you try to delete a property on window
// http://stackoverflow.com/a/1824228/751089
Expand All @@ -37,7 +35,9 @@

function removeScript(scriptId) {
var script = document.getElementById(scriptId);
document.getElementsByTagName('head')[0].removeChild(script);
if (script) {
document.getElementsByTagName('head')[0].removeChild(script);
}
}

function fetchJsonp(_url) {
Expand Down Expand Up @@ -79,12 +79,6 @@
jsonpScript.setAttribute('charset', options.charset);
}
jsonpScript.id = scriptId;
jsonpScript.onerror = function () {
reject(new Error('JSONP request to ' + _url + ' failed'));

clearFunction(callbackFunction);
removeScript(scriptId);
};
document.getElementsByTagName('head')[0].appendChild(jsonpScript);

timeoutId = setTimeout(function () {
Expand All @@ -93,6 +87,15 @@
clearFunction(callbackFunction);
removeScript(scriptId);
}, timeout);

// Caught if got 404/500
jsonpScript.onerror = function () {
reject(new Error('JSONP request to ' + _url + ' failed'));

clearFunction(callbackFunction);
removeScript(scriptId);
if (timeoutId) clearTimeout(timeoutId);
};
});
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "fetch-jsonp",
"version": "1.1.0",
"version": "1.1.1",
"description": "Fetch JSONP like a boss using Fetch API",
"main": "build/fetch-jsonp.js",
"scripts": {
"prepublish": "npm run lint && npm run clean && npm run build",
"test": "mocha --compilers js:babel/register --recursive --ui bdd --reporter spec",
"build": "babel src/ --modules umd --out-dir build",
"clean": "rm -rf build",
Expand Down

0 comments on commit 7fb44c5

Please sign in to comment.