From 6446697bfee061ff257cd445759097e1a76d98de Mon Sep 17 00:00:00 2001 From: William Toohey Date: Sat, 6 Feb 2016 03:09:29 +1000 Subject: [PATCH] Throw HTTP status codes for failed respack loads --- src/js/ResourcePack.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/js/ResourcePack.js b/src/js/ResourcePack.js index a3f005d..5da7400 100644 --- a/src/js/ResourcePack.js +++ b/src/js/ResourcePack.js @@ -92,10 +92,14 @@ Respack.prototype.getBlob = function(url, progress) { req.open('GET', url, true); req.responseType = 'blob'; req.onload = () => { - resolve(req.response); + if(req.status == 200) { + resolve(req.response); + } else { + reject(Error(req.status + ": Could not fetch respack at " + url)); + } }; req.onerror = function() { - reject(Error("Could not fetch respack at URL" + url)); + reject(Error(req.status + ": Could not fetch respack at " + url)); }; req.onprogress = event => { if (event.lengthComputable) { @@ -109,8 +113,12 @@ Respack.prototype.getBlob = function(url, progress) { }; req.send(); }).catch(error => { - // Infinitely more useful than the error Same Origin gives - throw Error("Could not fetch respack at URL" + url); + // Infinitely more user friendly than the error Same Origin gives + if(error.code == 1012) { + throw Error("Respack at URL " + url + " is restricted. Check CORS."); + } else { + throw error; + } }); }