Commit 3ad0af570af1a2fdd8db4926b8b36617cb425921

Golmote 2014-12-12T08:20:57

Reject promise if file does not exist

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);
 		}