-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement logout functionality and improve error handling across the app #707
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,38 @@ | ||
| import { checkRateLimit, getAuthenticatedUserId, getRatelimitModule, processIP } from '../../utils'; | ||
| import { | ||
| checkRateLimit, | ||
| getAuthenticatedUserId, | ||
| getRatelimitModule, | ||
| logoutUser, | ||
| processIP, | ||
| } from '../../utils'; | ||
| import { type NextRequest, NextResponse } from 'next/server'; | ||
| import { getActiveDriver } from '@/actions/utils'; | ||
| import { Ratelimit } from '@upstash/ratelimit'; | ||
|
|
||
| export const GET = async (req: NextRequest) => { | ||
| const userId = await getAuthenticatedUserId(); | ||
| const finalIp = processIP(req); | ||
| const ratelimit = getRatelimitModule({ | ||
| prefix: `ratelimit:get-count-${userId}`, | ||
| limiter: Ratelimit.slidingWindow(60, '1m'), | ||
| }); | ||
| const { success, headers } = await checkRateLimit(ratelimit, finalIp); | ||
| if (!success) { | ||
| return NextResponse.json( | ||
| { error: 'Too many requests. Please try again later.' }, | ||
| { status: 429, headers }, | ||
| ); | ||
| try { | ||
| const userId = await getAuthenticatedUserId(); | ||
| const finalIp = processIP(req); | ||
| const ratelimit = getRatelimitModule({ | ||
| prefix: `ratelimit:get-count-${userId}`, | ||
| limiter: Ratelimit.slidingWindow(60, '1m'), | ||
| }); | ||
| const { success, headers } = await checkRateLimit(ratelimit, finalIp); | ||
| if (!success) { | ||
| return NextResponse.json( | ||
| { error: 'Too many requests. Please try again later.' }, | ||
| { status: 429, headers }, | ||
| ); | ||
| } | ||
| const driver = await getActiveDriver(); | ||
| const count = await driver.count(); | ||
| return NextResponse.json(count, { | ||
| status: 200, | ||
| headers, | ||
| }); | ||
| } catch (error) { | ||
| console.warn('Error getting count:', error); | ||
| await logoutUser(); | ||
| return NextResponse.json({}); | ||
| } | ||
| const driver = await getActiveDriver(); | ||
| const count = await driver.count(); | ||
| return NextResponse.json(count, { | ||
| status: 200, | ||
| headers, | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,45 @@ | ||
| import { processIP, getRatelimitModule, checkRateLimit, getAuthenticatedUserId } from '../../utils'; | ||
| import { | ||
| processIP, | ||
| getRatelimitModule, | ||
| checkRateLimit, | ||
| getAuthenticatedUserId, | ||
| logoutUser, | ||
| } from '../../utils'; | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
| import { fetchThreadNotes } from '@/actions/notes'; | ||
| import { Ratelimit } from '@upstash/ratelimit'; | ||
| import { notesManager } from '../../notes/db'; | ||
|
|
||
| export const GET = async (req: NextRequest) => { | ||
| const userId = await getAuthenticatedUserId(); | ||
| const finalIp = processIP(req); | ||
| const ratelimit = getRatelimitModule({ | ||
| prefix: `ratelimit:get-thread-notes-${userId}`, | ||
| limiter: Ratelimit.slidingWindow(60, '1m'), | ||
| }); | ||
| const { success, headers } = await checkRateLimit(ratelimit, finalIp); | ||
| if (!success) { | ||
| return NextResponse.json( | ||
| { error: 'Too many requests. Please try again later.' }, | ||
| { status: 429, headers }, | ||
| ); | ||
| } | ||
| const searchParams = req.nextUrl.searchParams; | ||
| try { | ||
| const userId = await getAuthenticatedUserId(); | ||
| const finalIp = processIP(req); | ||
| const ratelimit = getRatelimitModule({ | ||
| prefix: `ratelimit:get-thread-notes-${userId}`, | ||
| limiter: Ratelimit.slidingWindow(60, '1m'), | ||
| }); | ||
| const { success, headers } = await checkRateLimit(ratelimit, finalIp); | ||
| if (!success) { | ||
| return NextResponse.json( | ||
| { error: 'Too many requests. Please try again later.' }, | ||
| { status: 429, headers }, | ||
| ); | ||
| } | ||
| const searchParams = req.nextUrl.searchParams; | ||
|
|
||
| if (!searchParams.get('threadId')) { | ||
| return NextResponse.json({ error: 'Missing threadId' }, { status: 400 }); | ||
| } | ||
| if (!searchParams.get('threadId')) { | ||
| return NextResponse.json({ error: 'Missing threadId' }, { status: 400 }); | ||
| } | ||
|
|
||
| const notes = await notesManager.getThreadNotes(userId, searchParams.get('threadId')!); | ||
| const notes = await notesManager.getThreadNotes(userId, searchParams.get('threadId')!); | ||
|
|
||
| return NextResponse.json(notes, { | ||
| status: 200, | ||
| headers, | ||
| }); | ||
| return NextResponse.json(notes, { | ||
| status: 200, | ||
| headers, | ||
| }); | ||
| } catch (error) { | ||
| console.warn('Error getting thread notes:', error); | ||
| await logoutUser(); | ||
| return NextResponse.json([]); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💡 Verification agent
🧩 Analysis chain
Removed retry logic for Gmail API calls.
The removal of the
withExponentialBackoffwrapper means the Gmail API call no longer has built-in retry logic for rate limiting issues.This change could reduce the resilience to transient rate limit errors. Ensure that rate limit handling is implemented elsewhere, or consider restoring the retry logic:
🏁 Script executed:
Length of output: 25720
🏁 Script executed:
Length of output: 4553
Add retry with exponential backoff to the
listcallThe
listmethod inapps/mail/app/api/driver/google.tsnow invokesgmail.users.threads.listdirectly, whereas thegetmethod still uses yourwithExponentialBackoffwrapper. Without backoff retries, transient 429/rate‑limit errors will surface immediately, reducing resilience.• File:
apps/mail/app/api/driver/google.ts• Around lines ~528–536
Suggested change:
list: async ( folder: string, q: string, maxResults = 20, _labelIds: string[] = [], pageToken?: string, ) => { const { folder: normalizedFolder, q: normalizedQ } = normalizeSearch(folder, q ?? ''); const labelIds = [..._labelIds]; if (normalizedFolder) labelIds.push(normalizedFolder.toUpperCase()); - const res = await gmail.users.threads.list({ - userId: 'me', - q: normalizedQ || undefined, - labelIds: folder === 'inbox' ? labelIds : [], - maxResults, - pageToken: pageToken || undefined, - quotaUser: config.auth?.email, - }); - return { ...res.data, threads: res.data.threads } as any; + return withExponentialBackoff(async () => { + const res = await gmail.users.threads.list({ + userId: 'me', + q: normalizedQ || undefined, + labelIds: folder === 'inbox' ? labelIds : [], + maxResults, + pageToken: pageToken || undefined, + quotaUser: config.auth?.email, + }); + return { ...res.data, threads: res.data.threads } as any; + }); },This restores automatic retries on rate‑limit and other transient errors, matching your existing
getimplementation.📝 Committable suggestion