Handle errors in ensureInit()

This commit is contained in:
goat 2021-05-26 23:34:40 +02:00
parent dd4d66dad4
commit 0ff6f8ce94
No known key found for this signature in database
GPG key ID: F18F057873895461

View file

@ -41,11 +41,11 @@ app.get('/prepare/id/:charaId', async (req, res) => {
diskCache.wrap(cacheKey,
// called if the cache misses in order to generate the value to cache
function (cb) {
creator.ensureInit().then(() => creator.createCard(req.params.charaId).then(image => cb(null, {
creator.ensureInit().then(() => creator.createCard(req.params.charaId), (reason) => cb('Init failed: ' + reason, null)).then(image => cb(null, {
binary: {
image: image,
}
})).catch((reason) => cb(reason, null)));
})).catch((reason) => cb('createCard failed: ' + reason, null));
},
// Options, see node-cache-manager for more examples
{ ttl: ttl },
@ -79,11 +79,11 @@ app.get('/characters/id/:charaId.png', async (req, res) => {
diskCache.wrap(cacheKey,
// called if the cache misses in order to generate the value to cache
function (cb) {
creator.ensureInit().then(() => creator.createCard(req.params.charaId).then(image => cb(null, {
creator.ensureInit().then(() => creator.createCard(req.params.charaId), (reason) => cb('Init failed: ' + reason, null)).then(image => cb(null, {
binary: {
image: image,
}
})).catch((reason) => cb(reason, null)));
})).catch((reason) => cb('createCard failed: ' + reason, null));
},
// Options, see node-cache-manager for more examples
{ ttl: ttl },