-
Notifications
You must be signed in to change notification settings - Fork 169
fix: improve error handling #1100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ export async function PATCH(req: Request, { params }: { params: Promise<{ id: st | |
| const email = user?.primaryEmailAddress?.emailAddress; | ||
|
|
||
| const { id } = await params; | ||
| const doubtId = parseInt(id); | ||
| const doubtId = parseInt(id, 10); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Using Severity Level: Critical 🚨- ❌ Crafted URLs can mutate an unintended doubt record.
- ⚠️ PATCH actions accept malformed identifiers.
- ⚠️ Client errors become incorrect mutations or lookups.(Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** src/app/api/doubts/action/[id]/route.ts
**Line:** 25:25
**Comment:**
*Api Mismatch: Using `parseInt` accepts partially numeric route parameters such as `123abc` and `123.4`, silently converting them to doubt ID `123`. Because this handler performs mutations after the lookup, a malformed URL can update or like the wrong doubt instead of returning a client error. Validate that the entire parameter is a canonical positive integer before parsing.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
|
|
||
| if (isNaN(doubtId)) { | ||
| return NextResponse.json({ error: "Invalid doubt ID" }, { status: 400 }); | ||
|
|
@@ -320,7 +320,7 @@ export async function DELETE(req: Request, { params }: { params: Promise<{ id: s | |
| } | ||
|
|
||
| const { id } = await params; | ||
| const doubtId = parseInt(id); | ||
| const doubtId = parseInt(id, 10); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The DELETE handler parses the route ID but never checks for Severity Level: Major
|
||
|
|
||
| const [doubt] = await db.select().from(doubtsTable).where(and(eq(doubtsTable.id, doubtId), isNull(doubtsTable.deletedAt))).limit(1); | ||
| if (!doubt) return NextResponse.json({ error: "Doubt not found" }, { status: 404 }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The client now sends the selected date range, but the analytics API switches to demo data whenever fewer than three doubts exist and always generates only seven trend points. Selecting 30 or 90 days therefore displays and exports preview trends covering seven days while labeling them as the selected range, producing misleading analytics. The demo trend generation must use the requested range or the UI must clearly indicate that the preview is fixed to seven days. [api mismatch]
Severity Level: Major⚠️
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖