diff --git a/backend/src/routes/logbooks-route.js b/backend/src/routes/logbooks-route.js index a846f795..ca8b116c 100644 --- a/backend/src/routes/logbooks-route.js +++ b/backend/src/routes/logbooks-route.js @@ -26,12 +26,20 @@ router.post("/:logbookID/logs", auth, async (req, res) => { router.get("/:logbookID/logs", auth, async (req, res) => { const logbookLogs = await getLogbookLogs(req); - res.status(200).json({ data: logbookLogs }); + if (logbookLogs.error) { + res.status(500).json({ error: logbookLogs.error }); + } else { + res.status(200).json({ data: logbookLogs }); + } }); router.get("/:logbookID/logs/:logID", auth, async (req, res) => { const log = await getLog(req); - res.status(200).json({ data: log }); + if (log.error) { + res.status(500).json({ error: log.error }); + } else { + res.status(200).json({ data: log }); + } }); export default router; \ No newline at end of file diff --git a/backend/src/services/logbooks-service.js b/backend/src/services/logbooks-service.js index cdcba939..ecf9b1c2 100644 --- a/backend/src/services/logbooks-service.js +++ b/backend/src/services/logbooks-service.js @@ -212,7 +212,8 @@ export async function getLogbookLogs(req) { } return data; } catch (error) { - throw new Error(error.message); + console.error(error.message); + return {error: error.message} } } @@ -227,6 +228,7 @@ export async function getLog(req) { } return data[0]; } catch (error) { - throw new Error(error.message); + console.error(error.message); + return {error: error.message} } }