mirror of https://github.com/buster-so/buster.git
Add more error handling for get report
This commit is contained in:
parent
01add5df25
commit
7a45e20903
|
@ -9,15 +9,14 @@ export async function getReportHandler(
|
||||||
reportId: string,
|
reportId: string,
|
||||||
user: { id: string }
|
user: { id: string }
|
||||||
): Promise<GetReportIndividualResponse> {
|
): Promise<GetReportIndividualResponse> {
|
||||||
const report = await getReport({ reportId, userId: user.id });
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const report = await getReport({ reportId, userId: user.id });
|
||||||
|
|
||||||
const platejsResult = await markdownToPlatejs(report.content);
|
const platejsResult = await markdownToPlatejs(report.content);
|
||||||
|
|
||||||
if (platejsResult.error) {
|
if (platejsResult.error) {
|
||||||
console.error('Error converting markdown to PlateJS:', platejsResult.error);
|
|
||||||
throw new HTTPException(500, {
|
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;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error converting markdown to PlateJS:', error);
|
console.error('Error getting report:', error);
|
||||||
throw new HTTPException(500, {
|
throw new HTTPException(500, {
|
||||||
message: 'Error converting markdown',
|
message: `Error getting report: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useMemo } from 'react';
|
import React from 'react';
|
||||||
import { Card, CardHeader } from '@/components/ui/card/CardBase';
|
import { Card, CardHeader } from '@/components/ui/card/CardBase';
|
||||||
import { MetricTitle } from './MetricTitle';
|
import { MetricTitle } from './MetricTitle';
|
||||||
import type { BusterMetric, BusterMetricData } from '@/api/asset_interfaces/metric';
|
import type { BusterMetric, BusterMetricData } from '@/api/asset_interfaces/metric';
|
||||||
|
@ -107,3 +107,5 @@ export const MetricCard = React.forwardRef<
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
MetricCard.displayName = 'MetricCard';
|
||||||
|
|
|
@ -3,16 +3,22 @@ import type { Descendant } from 'platejs';
|
||||||
import { SERVER_EDITOR } from './server-editor';
|
import { SERVER_EDITOR } from './server-editor';
|
||||||
|
|
||||||
export const markdownToPlatejs = async (markdown: string) => {
|
export const markdownToPlatejs = async (markdown: string) => {
|
||||||
const descendants = SERVER_EDITOR.api.markdown.deserialize(markdown);
|
try {
|
||||||
|
const descendants = SERVER_EDITOR.api.markdown.deserialize(markdown);
|
||||||
|
|
||||||
const safeParsedElements = ReportElementsSchema.safeParse(descendants);
|
const safeParsedElements = ReportElementsSchema.safeParse(descendants);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: safeParsedElements.error,
|
error: safeParsedElements.error,
|
||||||
elements: safeParsedElements.data,
|
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> => {
|
export const platejsToMarkdown = async (elements: ReportElements): Promise<string> => {
|
||||||
|
|
Loading…
Reference in New Issue