From 210760f5557462b878fb7a7c1dc3c1d648fa6d57 Mon Sep 17 00:00:00 2001 From: tryb3l <56679619+tryb3l@users.noreply.github.com> Date: Wed, 28 Aug 2024 22:48:20 +0200 Subject: [PATCH] update readnote handler --- routes/notes/routes.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/routes/notes/routes.js b/routes/notes/routes.js index 91e59ef..488213e 100644 --- a/routes/notes/routes.js +++ b/routes/notes/routes.js @@ -57,13 +57,19 @@ module.exports = async function noteRoutes(fastify) { }, }, handler: async function readNote(request, reply) { - const note = await request.notesDataSource.readNote(request.params.id) - if (!note) { - reply.code(404) - return { error: 'Record is not found' } + try { + const note = await this.notesDataSource.readNote(request.params.id) + if (!note) { + reply.code(404) + return { error: 'Note not found' } + } + + return { data: note } + } catch (error) { + console.error('Error fetching note details:', error) + reply.code(500) + return { error: 'Internal Server Error' } } - reply.code(201) - return note }, })