Skip to content

Commit

Permalink
do not fail rendering when request timeout occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsayen committed Mar 30, 2016
1 parent 52d85f2 commit 121061c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dist/dom-to-image.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/dom-to-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
function getAndEncode(url) {
var TIMEOUT = 30000;

return new Promise(function (resolve, reject) {
return new Promise(function (resolve) {
var request = new XMLHttpRequest();

request.onreadystatechange = done;
Expand All @@ -384,8 +384,7 @@
if (request.readyState !== 4) return;

if (request.status !== 200) {
console.error('cannot fetch resource ' + url + ', status: ' + request.status);
resolve('');
fail('cannot fetch resource: ' + url + ', status: ' + request.status);
return;
}

Expand All @@ -398,7 +397,12 @@
}

function timeout() {
reject(new Error('Timeout of ' + TIMEOUT + 'ms occured while fetching resource: ' + url));
fail('timeout of ' + TIMEOUT + 'ms occured while fetching resource: ' + url);
}

function fail(message){
console.error(message);
resolve('');
}
});
}
Expand Down

0 comments on commit 121061c

Please sign in to comment.