Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/frontend/src/pages/document/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const Document = (): JSX.Element => {
setIsLoading(true); // Step 2
try {
const response = await documentRead(id);
Copy link
Preview

Copilot AI May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before calling response.json(), check response.ok and handle non-2xx statuses explicitly to avoid parsing errors on a failed request.

Suggested change
const response = await documentRead(id);
const response = await documentRead(id);
if (!response.ok) {
throw new Error(`Failed to fetch document: ${response.status} ${response.statusText}`);
}

Copilot uses AI. Check for mistakes.

const data = await response.json();
setDocument(data);
const data: DocumentData = await response.json(); // Parse response as JSON
setDocument(data); // Use the parsed and typed data
} catch (error) {
console.error(error);
setDocument(null);
Expand All @@ -30,7 +30,7 @@ const Document = (): JSX.Element => {
};

if (params.id) {
getDocument(params.id);
getDocument(params.id as string); //
Copy link
Preview

Copilot AI May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of casting params.id with as string, you can type your route params when calling useParams<{ id: string }>() to avoid manual casting.

Suggested change
getDocument(params.id as string); //
getDocument(params.id); //

Copilot uses AI. Check for mistakes.

}
}, [params.id]);

Expand All @@ -41,7 +41,7 @@ const Document = (): JSX.Element => {
) : document ? (
<p>{document.content}</p>
) : (
<h1>Document not found. Please try again.</h1>
<p>Document not found. Please try again.</p>
)}
</>
);
Expand Down
Loading