From 41731dae73ae17eae35bf9fef9af2b413a098994 Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 15:42:48 +0100 Subject: [PATCH] Pages corrections pages missions --- components/carnet/editor.tsx | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/components/carnet/editor.tsx b/components/carnet/editor.tsx index f7a2f0c..7937ed8 100644 --- a/components/carnet/editor.tsx +++ b/components/carnet/editor.tsx @@ -44,6 +44,15 @@ export const Editor: React.FC = ({ note, onSave, currentFolder = 'N useEffect(() => { const fetchNoteContent = async () => { if (note?.id) { + // Skip fetching if id is temporary (starts with 'temp-') + // Temporary ids are used for new notes that haven't been saved yet + if (note.id.startsWith('temp-')) { + console.log(`Skipping fetch for temporary note id: ${note.id}`); + setIsLoading(false); + setContent(note.content || ''); + return; + } + // If content is already provided (e.g., for mission files), use it directly if (note.content !== undefined && note.content !== '') { setContent(note.content); @@ -78,10 +87,32 @@ export const Editor: React.FC = ({ note, onSave, currentFolder = 'N router.push('/signin'); return; } + if (response.status === 404) { + // File not found - this is normal for new notes that haven't been saved yet + console.log(`Note not found (404) for id: ${note.id}, treating as new note`); + setContent(''); + setIsLoading(false); + return; + } + if (response.status === 403) { + // Unauthorized access - don't show error, just clear content + console.warn(`Unauthorized access to note: ${note.id}`); + setContent(''); + setError(null); // Don't show error for unauthorized access + setIsLoading(false); + return; + } if (!response.ok) { const errorData = await response.json().catch(() => ({})); const errorMessage = errorData.message || errorData.error || `Failed to fetch note content: ${response.status}`; - throw new Error(errorMessage); + // Only show error for non-404/403 errors + if (response.status !== 404 && response.status !== 403) { + throw new Error(errorMessage); + } else { + setContent(''); + setIsLoading(false); + return; + } } const data = await response.json(); setContent(data.content || ''); @@ -90,8 +121,15 @@ export const Editor: React.FC = ({ note, onSave, currentFolder = 'N noteContentCache.set(note.id, data.content || ''); } catch (error) { console.error('Error fetching note content:', error); + // Only show error if it's not a 404 or 403 (which we handle above) const errorMessage = error instanceof Error ? error.message : 'Failed to load note content. Please try again later.'; - setError(errorMessage); + // Don't show error for file not found or unauthorized - these are handled above + if (!errorMessage.includes('404') && !errorMessage.includes('403') && !errorMessage.includes('File not found') && !errorMessage.includes('Unauthorized')) { + setError(errorMessage); + } else { + setError(null); + setContent(''); + } } finally { setIsLoading(false); }