Add more error handling for get report

This commit is contained in:
Nate Kelley 2025-08-07 16:42:04 -06:00
parent 01add5df25
commit 7a45e20903
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 22 additions and 15 deletions

View File

@ -9,15 +9,14 @@ export async function getReportHandler(
reportId: string,
user: { id: string }
): Promise<GetReportIndividualResponse> {
try {
const report = await getReport({ reportId, userId: user.id });
try {
const platejsResult = await markdownToPlatejs(report.content);
if (platejsResult.error) {
console.error('Error converting markdown to PlateJS:', platejsResult.error);
throw new HTTPException(500, {
message: 'Error converting markdown to PlateJS',
message: `Error converting markdown to PlateJS: ${platejsResult.error.message}`,
});
}
@ -30,9 +29,9 @@ export async function getReportHandler(
return response;
} catch (error) {
console.error('Error converting markdown to PlateJS:', error);
console.error('Error getting report:', error);
throw new HTTPException(500, {
message: 'Error converting markdown',
message: `Error getting report: ${error instanceof Error ? error.message : 'Unknown error'}`,
});
}
}

View File

@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React from 'react';
import { Card, CardHeader } from '@/components/ui/card/CardBase';
import { MetricTitle } from './MetricTitle';
import type { BusterMetric, BusterMetricData } from '@/api/asset_interfaces/metric';
@ -107,3 +107,5 @@ export const MetricCard = React.forwardRef<
);
}
);
MetricCard.displayName = 'MetricCard';

View File

@ -3,6 +3,7 @@ import type { Descendant } from 'platejs';
import { SERVER_EDITOR } from './server-editor';
export const markdownToPlatejs = async (markdown: string) => {
try {
const descendants = SERVER_EDITOR.api.markdown.deserialize(markdown);
const safeParsedElements = ReportElementsSchema.safeParse(descendants);
@ -10,9 +11,14 @@ export const markdownToPlatejs = async (markdown: string) => {
return {
error: safeParsedElements.error,
elements: safeParsedElements.data,
descendants,
markdown,
};
} catch (error) {
console.error('Error converting markdown to PlateJS:', error);
return {
error: error as Error,
elements: [],
};
}
};
export const platejsToMarkdown = async (elements: ReportElements): Promise<string> => {