Skip to content

Commit f08c179

Browse files
committed
feat: error handling
1 parent d9d2d14 commit f08c179

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/packages/ce/src/ai/components/AIChatComponent.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface AIChatComponentProps {
4343
projectId: NamespaceProject['id']
4444
flowId?: Flow['id']
4545
prompt?: string
46-
onData?: (data: any) => void
46+
onData?: (data: any) => string | void
4747

4848
}
4949

@@ -72,8 +72,13 @@ export const AIChatComponent: React.FC<AIChatComponentProps> = (props) => {
7272
onData: (data) => {
7373
setIsAIActive(true)
7474
if (data.data.data?.aiGenerateFlow?.flow) {
75-
onData?.(data.data.data?.aiGenerateFlow)
76-
setPromptState("")
75+
const result = onData?.(data.data.data?.aiGenerateFlow)
76+
if (typeof result === "string") {
77+
setAiErrorMessage(result)
78+
} else {
79+
setPromptState("")
80+
}
81+
setExecutionIdentifier(null)
7782
} else if (data.data.data?.aiGenerateFlow?.flow === null) {
7883
setExecutionIdentifier(null)
7984
setAiErrorMessage("Generation failed. Try another model.")
@@ -83,6 +88,7 @@ export const AIChatComponent: React.FC<AIChatComponentProps> = (props) => {
8388
onError: () => {
8489
setIsAIActive(false)
8590
setAiErrorMessage("Generation failed. Try another model.")
91+
setExecutionIdentifier(null)
8692
},
8793
})
8894

src/packages/ce/src/flow/components/panels/FlowPanelControlComponent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ export const FlowPanelControlComponent: React.FC<FlowPanelControlComponentProps>
7474

7575
const onAIData = React.useCallback((payload: AiGenerateFlowSubscriptionPayload) => {
7676
const aiFlow = payload?.flow
77-
if (!aiFlow) return
77+
if (!aiFlow) return "No flow returned. Try again."
7878

7979
const currentFlow = flowService.getById(flowId, {namespaceId, projectId})
80-
if (!currentFlow) return
80+
if (!currentFlow) return "Flow not found. Try again."
8181

8282
const currentFlowName = currentFlow.name ?? undefined
8383
const existingNames = (flowService.values({namespaceId, projectId}) ?? [])
8484
.map(f => f.name)
8585
.filter((n): n is string => !!n && n !== currentFlowName)
8686

8787
const flowInput = mapAiGenerationFlowToFlowInput(aiFlow, {existingNames})
88-
if (!flowInput) return
88+
if (!flowInput) return "Invalid flow type. Try another model."
8989

9090
const oldFlowSnapshot: FlowView = JSON.parse(JSON.stringify(currentFlow))
9191

src/packages/ce/src/flow/pages/FlowOverviewPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ export const FlowOverviewPage: React.FC = () => {
6161

6262
const onAIData = React.useCallback((payload: AiGenerateFlowSubscriptionPayload) => {
6363
const aiFlow = payload?.flow
64-
if (!aiFlow) return
64+
if (!aiFlow) return "No flow returned. Try again."
6565

6666
const existingNames = (flowService.values({namespaceId, projectId}) ?? [])
6767
.map(f => f.name)
6868
.filter((n): n is string => !!n)
6969

7070
const flowInput = mapAiGenerationFlowToFlowInput(aiFlow, {existingNames})
71-
if (!flowInput) return
71+
if (!flowInput) return "Invalid flow type. Try another model."
7272

7373
flowService.flowCreate({
7474
flow: flowInput,

0 commit comments

Comments
 (0)