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