Skip to content

Commit 4c57751

Browse files
committed
fix(frontend): improve session recovery robustness and reset guards
- Restrict session auto-wipe to explicitly catch 404 HTTP status errors using AxiosError - Add guard in handleResetSession to alert and prevent users from resetting while a network request is pending - Refine code comments for temporary UI components
1 parent a9870ac commit 4c57751

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

frontend/atla/src/components/chat/ChatInterface.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,42 @@ import { MessageList } from './MessageList';
77
import { ChatInput } from './ChatInput';
88
import { Button } from '../ui/button';
99
import { RefreshCcw } from 'lucide-react';
10+
import type { AxiosError } from 'axios';
1011

1112
export function ChatInterface() {
1213
const { addMessage, sessionId, setSessionId, clearMessages, messages } = useChatStore();
1314

1415
// Use the session query to verify if the backend still remembers this session
1516
const {
1617
isError: isSessionError,
17-
isFetching: isFetchingSession
18+
isFetching: isFetchingSession,
19+
error: sessionError,
1820
} = useChatSession(sessionId);
1921

2022
// If the backend session doesn't exist (example: server restarted), wipe the local storage and start fresh
2123
useEffect(() => {
22-
if (isSessionError) {
24+
if (!isSessionError) return;
25+
26+
const status = (sessionError as AxiosError | null | undefined)?.response?.status;
27+
if (status === 404) {
2328
clearMessages();
2429
addMessage({
2530
role: 'assistant',
2631
content: "Oops! It looks like your previous session expired. Let's start a brand new plan! Where would you like to go?"
2732
});
2833
}
29-
}, [isSessionError, clearMessages, addMessage]);
34+
}, [isSessionError, sessionError, clearMessages, addMessage]);
3035

3136
const sendMessageMutation = useSendMessage();
3237
const submitClarificationMutation = useSubmitClarification();
3338

3439
const handleResetSession = () => {
40+
const hasPendingRequest = sendMessageMutation.isPending || submitClarificationMutation.isPending;
41+
if (hasPendingRequest) {
42+
window.alert( 'Please wait for the current response to finish before starting a new trip plan.');
43+
return;
44+
}
45+
3546
if (window.confirm("Are you sure you want to start a new trip plan? This will clear your current conversation.")) {
3647
clearMessages();
3748
}

0 commit comments

Comments
 (0)