Skip to content

Commit

Permalink
feat: Add error handling for failed message submission
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrodip committed May 5, 2024
1 parent 3d3827b commit 0524808
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions components/prompt-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TooltipContent,
TooltipTrigger
} from '@/components/ui/tooltip'
import { toast } from 'sonner'
import { useEnterSubmit } from '@/lib/hooks/use-enter-submit'
import { nanoid } from 'nanoid'
import { useRouter } from 'next/navigation'
Expand Down Expand Up @@ -62,8 +63,12 @@ export function PromptForm({
])

// Submit and get response message
const responseMessage = await submitUserMessage(value)
setMessages(currentMessages => [...currentMessages, responseMessage])
try {
const responseMessage = await submitUserMessage(value)
setMessages(currentMessages => [...currentMessages, responseMessage])
} catch (error) {
toast.error('Failed to send message.')
}
}}
>
<div className="relative flex max-h-60 w-full grow flex-col overflow-hidden bg-background px-8 sm:rounded-md sm:border sm:px-12">
Expand Down

0 comments on commit 0524808

Please sign in to comment.