Skip to content

Commit

Permalink
Return 500 if membership fetch fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Taylor committed Jan 16, 2024
1 parent 9d7e664 commit e6f7fdb
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions routes/membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit e6f7fdb

Please sign in to comment.