From 7911518b394d6793365190a5a656620aa5dd4131 Mon Sep 17 00:00:00 2001 From: HoldYourWaffle Date: Sat, 16 Feb 2019 13:34:36 +0100 Subject: [PATCH] Add stubs for error handling --- src/browser/index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/browser/index.js b/src/browser/index.js index 3b5a6b2..a28cd08 100644 --- a/src/browser/index.js +++ b/src/browser/index.js @@ -52,18 +52,22 @@ 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 } @@ -71,6 +75,7 @@ function loadImage(image, cb){ // 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){