Reject promise if file does not exist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/download.js b/download.js
index ccbeb23..44a7299 100644
--- a/download.js
+++ b/download.js
@@ -238,12 +238,14 @@ function getFilesSizes() {
getFilesSizes();
function getFileContents(filepath) {
- return new Promise(function(resolve) {
+ return new Promise(function(resolve, reject) {
$u.xhr({
url: filepath,
callback: function(xhr) {
if (xhr.status < 400) {
resolve(xhr.responseText);
+ } else {
+ reject();
}
}
});
@@ -350,6 +352,7 @@ function generateCode(){
promises.push({
contentsPromise: cache[path].contentsPromise,
+ path: path,
type: type
});
}
@@ -389,6 +392,11 @@ function buildCode(promises) {
i++;
f(resolve);
});
+ p.contentsPromise['catch'](function() {
+ code[p.type] += '/* Error downloading file '+p.path+' */' + '\n';
+ i++;
+ f(resolve);
+ });
} else {
resolve(code);
}