mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-31 21:42:44 +00:00
proper error handling(i think)
This commit is contained in:
@@ -46,6 +46,10 @@ const archive = {
|
||||
// No published documents found with the given title
|
||||
return res.status(404).json({ error: 'Published documents not found' });
|
||||
}
|
||||
if (!brews || brews.length === 0) {
|
||||
return res.status(404).json({ errorCode: '404', message: 'Published documents not found' });
|
||||
}
|
||||
|
||||
const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection);
|
||||
|
||||
const totalPages = Math.ceil(totalBrews / pageSize);
|
||||
@@ -54,7 +58,11 @@ const archive = {
|
||||
return res.json({ brews, page, totalPages, totalBrews});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ error: 'Internal Server Error' });
|
||||
if (error.response && error.response.status === 503) {
|
||||
return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' });
|
||||
} else {
|
||||
return res.status(500).json({ errorCode: '500', message: 'Internal Server Error' });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user