From 358e74149ae16a19d1959175bf100ec641bce025 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 7 Aug 2025 15:09:49 -0600 Subject: [PATCH] try catch wrap --- apps/server/src/api/v2/reports/[id]/GET.ts | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/apps/server/src/api/v2/reports/[id]/GET.ts b/apps/server/src/api/v2/reports/[id]/GET.ts index 7eb956a6c..ce2c2b1af 100644 --- a/apps/server/src/api/v2/reports/[id]/GET.ts +++ b/apps/server/src/api/v2/reports/[id]/GET.ts @@ -11,23 +11,30 @@ export async function getReportHandler( ): Promise { const report = await getReport({ reportId, userId: user.id }); - const platejsResult = await markdownToPlatejs(report.content); + try { + const platejsResult = await markdownToPlatejs(report.content); - if (platejsResult.error) { - console.error('Error converting markdown to PlateJS:', platejsResult.error); + if (platejsResult.error) { + console.error('Error converting markdown to PlateJS:', platejsResult.error); + throw new HTTPException(500, { + message: 'Error converting markdown to PlateJS', + }); + } + + const content = platejsResult.elements ?? []; + + const response: GetReportIndividualResponse = { + ...report, + content, + }; + + return response; + } catch (error) { + console.error('Error converting markdown to PlateJS:', error); throw new HTTPException(500, { - message: 'Error converting markdown to PlateJS', + message: 'Error converting markdown', }); } - - const content = platejsResult.elements ?? []; - - const response: GetReportIndividualResponse = { - ...report, - content, - }; - - return response; } const app = new Hono()