Merge pull request #229 from tschaub/handle-rejection
Handle promise rejection
This commit is contained in:
commit
27eb7f0ed8
5 changed files with 45 additions and 26 deletions
|
@ -37,7 +37,15 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
var source;
|
var source;
|
||||||
var sourceInfoPromise = new Promise(function(resolve, reject) {
|
var sourceInfoPromise = new Promise(function(resolve, reject) {
|
||||||
source = new mbtiles(mbtilesFile, function(err) {
|
source = new mbtiles(mbtilesFile, function(err) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
source.getInfo(function(err, info) {
|
source.getInfo(function(err, info) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
tileJSON['name'] = id;
|
tileJSON['name'] = id;
|
||||||
tileJSON['format'] = 'pbf';
|
tileJSON['format'] = 'pbf';
|
||||||
|
|
||||||
|
@ -176,9 +184,7 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
return res.send(info);
|
return res.send(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return sourceInfoPromise.then(function() {
|
||||||
sourceInfoPromise.then(function() {
|
return app;
|
||||||
resolve(app);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,14 +17,20 @@ module.exports = function(options, allowedFonts) {
|
||||||
var existingFonts = {};
|
var existingFonts = {};
|
||||||
var fontListingPromise = new Promise(function(resolve, reject) {
|
var fontListingPromise = new Promise(function(resolve, reject) {
|
||||||
fs.readdir(options.paths.fonts, function(err, files) {
|
fs.readdir(options.paths.fonts, function(err, files) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
files.forEach(function(file) {
|
files.forEach(function(file) {
|
||||||
fs.stat(path.join(fontPath, file), function(err, stats) {
|
fs.stat(path.join(fontPath, file), function(err, stats) {
|
||||||
if (!err) {
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (stats.isDirectory() &&
|
if (stats.isDirectory() &&
|
||||||
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
|
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
|
||||||
existingFonts[path.basename(file)] = true;
|
existingFonts[path.basename(file)] = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -54,9 +60,7 @@ module.exports = function(options, allowedFonts) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return fontListingPromise.then(function() {
|
||||||
fontListingPromise.then(function() {
|
return app;
|
||||||
resolve(app);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -122,13 +122,19 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||||
var existingFonts = {};
|
var existingFonts = {};
|
||||||
var fontListingPromise = new Promise(function(resolve, reject) {
|
var fontListingPromise = new Promise(function(resolve, reject) {
|
||||||
fs.readdir(options.paths.fonts, function(err, files) {
|
fs.readdir(options.paths.fonts, function(err, files) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
files.forEach(function(file) {
|
files.forEach(function(file) {
|
||||||
fs.stat(path.join(options.paths.fonts, file), function(err, stats) {
|
fs.stat(path.join(options.paths.fonts, file), function(err, stats) {
|
||||||
if (!err) {
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
existingFonts[path.basename(file)] = true;
|
existingFonts[path.basename(file)] = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -740,9 +746,8 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||||
return res.send(info);
|
return res.send(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return Promise.all([fontListingPromise, renderersReadyPromise]).then(function() {
|
||||||
Promise.all([fontListingPromise, renderersReadyPromise]).then(function() {
|
return app;
|
||||||
resolve(app);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -246,8 +246,9 @@ function start(opts) {
|
||||||
startupPromises.push(new Promise(function(resolve, reject) {
|
startupPromises.push(new Promise(function(resolve, reject) {
|
||||||
fs.readFile(templateFile, function(err, content) {
|
fs.readFile(templateFile, function(err, content) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Template not found:', err);
|
err = new Error('Template not found: ' + err.message);
|
||||||
reject(err);
|
reject(err);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
var compiled = handlebars.compile(content.toString());
|
var compiled = handlebars.compile(content.toString());
|
||||||
|
|
||||||
|
@ -415,6 +416,11 @@ function start(opts) {
|
||||||
module.exports = function(opts) {
|
module.exports = function(opts) {
|
||||||
var running = start(opts);
|
var running = start(opts);
|
||||||
|
|
||||||
|
running.startupPromise.catch(function(err) {
|
||||||
|
console.error(err.message);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
process.on('SIGINT', function() {
|
process.on('SIGINT', function() {
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
|
|
|
@ -110,9 +110,7 @@ module.exports.getFontsPbf = function(allowedFonts, fontPath, names, range, fall
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return Promise.all(queue).then(function(values) {
|
||||||
Promise.all(queue).then(function(values) {
|
return glyphCompose.combine(values);
|
||||||
return resolve(glyphCompose.combine(values));
|
|
||||||
}, reject);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue