Skip to content

Commit 4d22430

Browse files
committed
add messageInstance for throwing errors in attachments for AI chat component
1 parent a46c1f7 commit 4d22430

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

client/packages/lowcoder/src/comps/comps/chatComp/utils/attachmentAdapter.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
Attachment,
66
ThreadUserContentPart
77
} from "@assistant-ui/react";
8+
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
89

910
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10 MB
1011

@@ -13,6 +14,9 @@ import type {
1314

1415
async add({ file }): Promise<PendingAttachment> {
1516
if (file.size > MAX_FILE_SIZE) {
17+
messageInstance.error(
18+
`File "${file.name}" exceeds the 10 MB size limit (${(file.size / 1024 / 1024).toFixed(1)} MB).`
19+
);
1620
throw new Error(
1721
`File "${file.name}" exceeds the 10 MB size limit (${(file.size / 1024 / 1024).toFixed(1)} MB).`
1822
);
@@ -48,9 +52,9 @@ import type {
4852
mimeType: attachment.file.type,
4953
}];
5054
} catch (err) {
51-
throw new Error(
52-
`Failed to process attachment "${attachment.name}": ${err instanceof Error ? err.message : "unknown error"}`
53-
);
55+
const errorMessage = `Failed to process attachment "${attachment.name}": ${err instanceof Error ? err.message : "unknown error"}`;
56+
messageInstance.error(errorMessage);
57+
throw new Error(errorMessage);
5458
}
5559

5660
return {

0 commit comments

Comments
 (0)