Skip to content

Commit ee4c4e5

Browse files
Toast on error in mlEphantManagerMachine (#8148)
* pierremtb/issue8087-toast-on-error * Update snapshots * Update to have only the message in the particular error I was looking at * Update snapshots * Reset snaps * Dumb me this ain't main --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent add4e86 commit ee4c4e5

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/lib/promptToEdit.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export async function submitTextToCadMultiFileIterationRequest(
5959

6060
if (!response.ok) {
6161
const errorBody = await response.json()
62+
if ('message' in errorBody) {
63+
return new Error(errorBody.message)
64+
}
65+
6266
return new Error(
6367
`HTTP error! status: ${response.status}, error: ${JSON.stringify(errorBody)}`
6468
)

src/machines/mlEphantManagerMachine.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
submitTextToCadMultiFileIterationRequest,
2929
constructMultiFileIterationRequestWithPromptHelpers,
3030
} from '@src/lib/promptToEdit'
31+
import toast from 'react-hot-toast'
3132

3233
const MLEPHANT_POLL_STATUSES_MS = 5000
3334

@@ -182,6 +183,18 @@ export const mlEphantManagerMachine = setup({
182183
context: {} as MlEphantManagerContext,
183184
events: {} as MlEphantManagerEvents,
184185
},
186+
actions: {
187+
toastError: ({ event }) => {
188+
console.error(event)
189+
if ('output' in event && event.output instanceof Error) {
190+
toast.error(event.output.message)
191+
} else if ('data' in event && event.data instanceof Error) {
192+
toast.error(event.data.message)
193+
} else if ('error' in event && event.error instanceof Error) {
194+
toast.error(event.error.message)
195+
}
196+
},
197+
},
185198
actors: {
186199
[MlEphantManagerTransitions.GetConversationsThatCreatedProjects]:
187200
fromPromise(async function (args: {
@@ -553,7 +566,7 @@ export const mlEphantManagerMachine = setup({
553566
// On failure we need correct dependencies still.
554567
onError: {
555568
target: MlEphantManagerStates.NeedDependencies,
556-
actions: console.error,
569+
actions: 'toastError',
557570
},
558571
},
559572
},
@@ -582,7 +595,7 @@ export const mlEphantManagerMachine = setup({
582595
target: S.Await,
583596
actions: assign(({ event }) => event.output),
584597
},
585-
onError: { target: S.Await, actions: console.error },
598+
onError: { target: S.Await, actions: 'toastError' },
586599
},
587600
},
588601
},
@@ -625,7 +638,7 @@ export const mlEphantManagerMachine = setup({
625638
target: S.Await,
626639
actions: assign(({ event }) => event.output),
627640
},
628-
onError: { target: S.Await, actions: console.error },
641+
onError: { target: S.Await, actions: 'toastError' },
629642
},
630643
},
631644
[MlEphantManagerTransitions.GetPromptsBelongingToConversation]: {
@@ -640,7 +653,7 @@ export const mlEphantManagerMachine = setup({
640653
target: S.Await,
641654
actions: assign(({ event }) => event.output),
642655
},
643-
onError: { target: S.Await, actions: console.error },
656+
onError: { target: S.Await, actions: 'toastError' },
644657
},
645658
},
646659
[MlEphantManagerTransitions.GetReasoningForPrompt]: {
@@ -670,7 +683,7 @@ export const mlEphantManagerMachine = setup({
670683
target: S.Await,
671684
actions: assign(({ event }) => event.output),
672685
},
673-
onError: { target: S.Await, actions: console.error },
686+
onError: { target: S.Await, actions: 'toastError' },
674687
},
675688
},
676689
[MlEphantManagerTransitions.PromptCreateModel]: {
@@ -685,7 +698,7 @@ export const mlEphantManagerMachine = setup({
685698
target: MlEphantManagerTransitions.GetReasoningForPrompt,
686699
actions: assign(({ event }) => event.output),
687700
},
688-
onError: { target: S.Await, actions: console.error },
701+
onError: { target: S.Await, actions: 'toastError' },
689702
},
690703
},
691704
[MlEphantManagerTransitions.PromptEditModel]: {
@@ -700,7 +713,7 @@ export const mlEphantManagerMachine = setup({
700713
target: MlEphantManagerTransitions.GetReasoningForPrompt,
701714
actions: assign(({ event }) => event.output),
702715
},
703-
onError: { target: S.Await, actions: console.error },
716+
onError: { target: S.Await, actions: 'toastError' },
704717
},
705718
},
706719
[MlEphantManagerTransitions.PromptFeedback]: {
@@ -715,7 +728,7 @@ export const mlEphantManagerMachine = setup({
715728
target: S.Await,
716729
actions: assign(({ event }) => event.output),
717730
},
718-
onError: { target: S.Await, actions: console.error },
731+
onError: { target: S.Await, actions: 'toastError' },
719732
},
720733
},
721734
[MlEphantManagerTransitions.AppendThoughtForPrompt]: {

0 commit comments

Comments
 (0)