From 0ff6f8ce9428c5cd9ca530cd84940c7dce838582 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Wed, 26 May 2021 23:34:40 +0200 Subject: [PATCH] Handle errors in ensureInit() --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ee829a9..2c9149a 100644 --- a/index.js +++ b/index.js @@ -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 },