fix: handle 404 errors for deleted assistant conversations

When a stored conversation ID no longer exists (e.g., database was reset
or conversation was deleted), the UI would repeatedly try to fetch it,
causing endless 404 errors in the console.

This fix:
- Stops retrying on 404 errors (conversation doesn't exist)
- Automatically clears the stored conversation ID from localStorage
  when a 404 is received, allowing the user to start fresh

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
nioasoft
2026-01-26 12:26:06 +02:00
parent a437af7f96
commit 468e59f86c
2 changed files with 16 additions and 1 deletions

View File

@@ -49,11 +49,19 @@ export function AssistantPanel({ projectName, isOpen, onClose }: AssistantPanelP
) )
// Fetch conversation details when we have an ID // Fetch conversation details when we have an ID
const { data: conversationDetail, isLoading: isLoadingConversation } = useConversation( const { data: conversationDetail, isLoading: isLoadingConversation, error: conversationError } = useConversation(
projectName, projectName,
conversationId conversationId
) )
// Clear stored conversation ID if it no longer exists (404 error)
useEffect(() => {
if (conversationError && conversationId) {
console.warn(`Conversation ${conversationId} not found, clearing stored ID`)
setConversationId(null)
}
}, [conversationError, conversationId])
// Convert API messages to ChatMessage format for the chat component // Convert API messages to ChatMessage format for the chat component
const initialMessages: ChatMessage[] | undefined = conversationDetail?.messages.map((msg) => ({ const initialMessages: ChatMessage[] | undefined = conversationDetail?.messages.map((msg) => ({
id: `db-${msg.id}`, id: `db-${msg.id}`,

View File

@@ -26,6 +26,13 @@ export function useConversation(projectName: string | null, conversationId: numb
queryFn: () => api.getAssistantConversation(projectName!, conversationId!), queryFn: () => api.getAssistantConversation(projectName!, conversationId!),
enabled: !!projectName && !!conversationId, enabled: !!projectName && !!conversationId,
staleTime: 30_000, // Cache for 30 seconds staleTime: 30_000, // Cache for 30 seconds
retry: (failureCount, error) => {
// Don't retry on 404 errors (conversation doesn't exist)
if (error instanceof Error && error.message.includes('404')) {
return false
}
return failureCount < 3
},
}) })
} }