mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-09 15:52:40 +02:00
refactor: implement error handling for video download and PPTX export in video presentation component
This commit is contained in:
parent
fde8faec7e
commit
c894185102
2 changed files with 44 additions and 6 deletions
|
|
@ -0,0 +1,38 @@
|
||||||
|
export function getVideoDownloadErrorToast(err: unknown): { title: string; description: string } {
|
||||||
|
const msg = err instanceof Error ? err.message.toLowerCase() : "";
|
||||||
|
|
||||||
|
if (msg.includes("webcodecs") || msg.includes("canrendermediaonweb") || msg.includes("not support")) {
|
||||||
|
return {
|
||||||
|
title: "Browser Not Supported",
|
||||||
|
description: "Video rendering requires Chrome, Edge, or Firefox 130+.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.includes("memory") || msg.includes("oom") || msg.includes("allocation")) {
|
||||||
|
return {
|
||||||
|
title: "Out of Memory",
|
||||||
|
description: "The presentation is too large to render. Try closing other tabs.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: "Download Failed",
|
||||||
|
description: "Something went wrong while rendering. Please try again.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPptxExportErrorToast(err: unknown): { title: string; description: string } {
|
||||||
|
const msg = err instanceof Error ? err.message.toLowerCase() : "";
|
||||||
|
|
||||||
|
if (msg.includes("dynamically imported") || msg.includes("failed to fetch") || msg.includes("network")) {
|
||||||
|
return {
|
||||||
|
title: "Export Unavailable",
|
||||||
|
description: "Could not load the export module. Check your network and try again.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: "PPTX Export Failed",
|
||||||
|
description: "Something went wrong while exporting. Please try again.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ import {
|
||||||
buildSlideWithWatermark,
|
buildSlideWithWatermark,
|
||||||
type CompiledSlide,
|
type CompiledSlide,
|
||||||
} from "./combined-player";
|
} from "./combined-player";
|
||||||
|
import { getVideoDownloadErrorToast, getPptxExportErrorToast } from "./errors";
|
||||||
|
|
||||||
const GenerateVideoPresentationArgsSchema = z.object({
|
const GenerateVideoPresentationArgsSchema = z.object({
|
||||||
source_content: z.string(),
|
source_content: z.string(),
|
||||||
|
|
@ -68,6 +69,7 @@ type GenerateVideoPresentationArgs = z.infer<typeof GenerateVideoPresentationArg
|
||||||
type GenerateVideoPresentationResult = z.infer<typeof GenerateVideoPresentationResultSchema>;
|
type GenerateVideoPresentationResult = z.infer<typeof GenerateVideoPresentationResultSchema>;
|
||||||
type VideoPresentationStatusResponse = z.infer<typeof VideoPresentationStatusResponseSchema>;
|
type VideoPresentationStatusResponse = z.infer<typeof VideoPresentationStatusResponseSchema>;
|
||||||
|
|
||||||
|
|
||||||
function parseStatusResponse(data: unknown): VideoPresentationStatusResponse | null {
|
function parseStatusResponse(data: unknown): VideoPresentationStatusResponse | null {
|
||||||
const result = VideoPresentationStatusResponseSchema.safeParse(data);
|
const result = VideoPresentationStatusResponseSchema.safeParse(data);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
|
|
@ -321,9 +323,8 @@ function VideoPresentationPlayer({
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if ((err as Error).name !== "AbortError") {
|
if ((err as Error).name !== "AbortError") {
|
||||||
toast.error("Download Failed", {
|
const { title, description } = getVideoDownloadErrorToast(err);
|
||||||
description: err instanceof Error ? err.message : "Failed to render video",
|
toast.error(title, { description });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsRendering(false);
|
setIsRendering(false);
|
||||||
|
|
@ -396,9 +397,8 @@ function VideoPresentationPlayer({
|
||||||
for (const r of roots) r.unmount();
|
for (const r of roots) r.unmount();
|
||||||
document.body.removeChild(offscreen);
|
document.body.removeChild(offscreen);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error("PPTX Export Failed", {
|
const { title, description } = getPptxExportErrorToast(err);
|
||||||
description: err instanceof Error ? err.message : "Failed to export PPTX",
|
toast.error(title, { description });
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsPptxExporting(false);
|
setIsPptxExporting(false);
|
||||||
setPptxProgress(null);
|
setPptxProgress(null);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue