Skip to content

Commit

Permalink
Add stubs for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HoldYourWaffle committed Feb 16, 2019
1 parent 06d32c6 commit 679eba0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,30 @@ function loadImage(image, cb){
var im = new Image
im.src = image;
im.onload = e => loadImage(im, cb);
//im.onerror = e => ?; TODO handle error
return
}else{
var xhr = new XMLHttpRequest();
xhr.open('GET', image, true)
xhr.responseType = "blob";
xhr.onload = e => loadImage(xhr.response, cb);
xhr.onerror = function(e){
if(/^https?:\/\//.test(image) && !/^https:\/\/crossorigin.me/.test(image)){
console.debug('Attempting to load image with CORS proxy')
loadImage('https://crossorigin.me/' + image, cb)

xhr.onload = e => {
if (xhr.status >= 400){
//TODO handle error
}else{
loadImage(xhr.response, cb);
}
}
};
//xhr.onerror = e => ?; TODO handle error

xhr.send(null)
return
}
}else if(image instanceof File){
// files
var fr = new FileReader()
fr.onload = e => loadImage(fr.result, cb);
//fr.onerror = e => ?; TODO handle error
fr.readAsDataURL(image)
return
}else if(image instanceof Blob){
Expand Down

0 comments on commit 679eba0

Please # to comment.