diff --git a/routes/membership.js b/routes/membership.js index c0650c8..3c1bc4f 100644 --- a/routes/membership.js +++ b/routes/membership.js @@ -301,17 +301,23 @@ router.get('/import', checkAdmin, async (req, res) => { url += `&product=${products[0].ExternalId}`; } - const data = await fetch(url, { - headers: { - Authorization: 'Basic ' + Buffer.from(`${config.Key}:${config.Secret}`).toString('base64') - } - }).then(res => res.json()); + let data = null; + try { + data = await fetch(url, { + headers: { + Authorization: 'Basic ' + Buffer.from(`${config.Key}:${config.Secret}`).toString('base64') + } + }).then(res => res.json()); + } catch { + return res.status(500).send(''); + } + const processor = new WPOrderProcessor(products, season, req.db); let memberships = []; - for (let o = 0; o < data.length; o++){ - const res = await processor.process(data[o]); + for (const element of data){ + const res = await processor.process(element); memberships = memberships.concat(res); }