Browse Source

Add stubs for error handling

pull/267/head
HoldYourWaffle 6 years ago
parent
commit
7911518b39
  1. 17
      src/browser/index.js

17
src/browser/index.js

@ -52,18 +52,22 @@ function loadImage(image, cb){
var im = new Image var im = new Image
im.src = image; im.src = image;
im.onload = e => loadImage(im, cb); im.onload = e => loadImage(im, cb);
//im.onerror = e => ?; TODO handle error
return return
}else{ }else{
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('GET', image, true) xhr.open('GET', image, true)
xhr.responseType = "blob"; xhr.responseType = "blob";
xhr.onload = e => loadImage(xhr.response, cb);
xhr.onerror = function(e){ xhr.onload = e => {
if(/^https?:\/\//.test(image) && !/^https:\/\/crossorigin.me/.test(image)){ if (xhr.status >= 400){
console.debug('Attempting to load image with CORS proxy') //TODO handle error
loadImage('https://crossorigin.me/' + image, cb) }else{
} loadImage(xhr.response, cb);
} }
};
//xhr.onerror = e => ?; TODO handle error
xhr.send(null) xhr.send(null)
return return
} }
@ -71,6 +75,7 @@ function loadImage(image, cb){
// files // files
var fr = new FileReader() var fr = new FileReader()
fr.onload = e => loadImage(fr.result, cb); fr.onload = e => loadImage(fr.result, cb);
//fr.onerror = e => ?; TODO handle error
fr.readAsDataURL(image) fr.readAsDataURL(image)
return return
}else if(image instanceof Blob){ }else if(image instanceof Blob){

Loading…
Cancel
Save