-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Staging #702
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
Staging #702
Changes from all commits
588ab02
1347a8e
373423b
cd8833b
49acc64
8dba8a9
7dd0fcd
0d4be12
e35bd3f
d1bcb68
f9f16db
e730552
85e8fbf
dd9f236
2398a61
93eb1d2
814fc48
749cabc
4d51e20
d3c72b5
972ddd0
4ee76c3
38d85e4
8f687d7
458b065
8a0a833
ca1bc22
a864044
03106ce
b73d3be
a71f0c4
9e22918
db58b12
9313985
14dfeed
2bdcd8d
cffc4f6
870dca9
32a698d
576cc73
c82605a
0e2d67a
61a4304
5945c96
e902575
7d094ad
c47a453
bbb5c15
45a35d1
1ef5490
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 |
|---|---|---|
| @@ -1,24 +1,20 @@ | ||
| 'use server' | ||
| import { auth } from "@/lib/auth"; | ||
| import { db } from "@zero/db"; | ||
| import { connection } from "@zero/db/schema"; | ||
| import { headers } from "next/headers"; | ||
| import { and, eq } from "drizzle-orm"; | ||
| import axios from "axios"; | ||
| import { getActiveConnection } from "./utils"; | ||
| 'use server'; | ||
| import { throwUnauthorizedGracefully } from '@/app/api/utils'; | ||
| import { getActiveConnection } from './utils'; | ||
| import axios from 'axios'; | ||
|
|
||
| export const EnableBrain = async () => { | ||
| if (!process.env.BRAIN_URL) { | ||
| throw new Error('Brain URL not found'); | ||
| } | ||
| if (!process.env.BRAIN_URL) { | ||
| return null; | ||
| } | ||
|
|
||
| const connection = await getActiveConnection() | ||
| const connection = await getActiveConnection(); | ||
|
|
||
| if (!connection?.accessToken || !connection.refreshToken) { | ||
| throw new Error("Unauthorized, reconnect"); | ||
| } | ||
| if (!connection?.accessToken || !connection.refreshToken) { | ||
| return throwUnauthorizedGracefully(); | ||
| } | ||
|
|
||
| return await axios.put(process.env.BRAIN_URL + `/subscribe/${connection.providerId}`, { | ||
| connectionId: connection.id, | ||
| }) | ||
| } | ||
| return await axios.put(process.env.BRAIN_URL + `/subscribe/${connection.providerId}`, { | ||
| connectionId: connection.id, | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||
| "use server"; | ||||||||||||||||
| import { getActiveDriver } from "./utils"; | ||||||||||||||||
| 'use server'; | ||||||||||||||||
| import { throwUnauthorizedGracefully } from '@/app/api/utils'; | ||||||||||||||||
| import { getActiveDriver } from './utils'; | ||||||||||||||||
|
|
||||||||||||||||
| export const getDrafts = async ({ | ||||||||||||||||
| q, | ||||||||||||||||
|
|
@@ -14,8 +15,9 @@ export const getDrafts = async ({ | |||||||||||||||
| const driver = await getActiveDriver(); | ||||||||||||||||
| return await driver.listDrafts(q, max, pageToken); | ||||||||||||||||
| } catch (error) { | ||||||||||||||||
| console.error("Error getting threads:", error); | ||||||||||||||||
| throw error; | ||||||||||||||||
| console.error('Error getting threads:', error); | ||||||||||||||||
| await throwUnauthorizedGracefully(); | ||||||||||||||||
| // throw error; | ||||||||||||||||
|
Comment on lines
+18
to
+20
Contributor
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. Improved error handling but missing return value The error handling now correctly uses the centralized utility for graceful handling of unauthorized errors. However, unlike in This could result in an try {
const driver = await getActiveDriver();
return await driver.listDrafts(q, max, pageToken);
} catch (error) {
console.error('Error getting threads:', error);
await throwUnauthorizedGracefully();
// throw error;
+ return { messages: [], nextPageToken: null };
}📝 Committable suggestion
Suggested change
|
||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -27,23 +29,23 @@ export const createDraft = async (data: any) => { | |||||||||||||||
|
|
||||||||||||||||
| return { success: true, id: res.id }; | ||||||||||||||||
| } catch (error) { | ||||||||||||||||
| console.error("Error creating draft:", error); | ||||||||||||||||
| console.error('Error creating draft:', error); | ||||||||||||||||
| return { success: false, error: String(error) }; | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| export const getDraft = async (id: string) => { | ||||||||||||||||
| if (!id) { | ||||||||||||||||
| throw new Error("Missing draft ID"); | ||||||||||||||||
| throw new Error('Missing draft ID'); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| console.log("getting email:", id); | ||||||||||||||||
| console.log('getting email:', id); | ||||||||||||||||
|
|
||||||||||||||||
| try { | ||||||||||||||||
| const driver = await getActiveDriver(); | ||||||||||||||||
| return await driver.getDraft(id); | ||||||||||||||||
| } catch (error) { | ||||||||||||||||
| console.error("Error getting draft:", error); | ||||||||||||||||
| console.error('Error getting draft:', error); | ||||||||||||||||
| throw error; | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
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
Verify return type compatibility with function signature.
The function is declared to return
Promise<AIEmailResponse>, but now it can return the result ofthrowUnauthorizedGracefully()which redirects to the login page. This creates a potential type inconsistency.🏁 Script executed:
Length of output: 180
🏁 Script executed:
Length of output: 367
Ensure return type consistency for the unauthorized flow
The
ai.tsaction is declared to returnPromise<AIEmailResponse>, but on an unauthenticated session you’re doing:Here
throwUnauthorizedGracefully()is anasynchelper that ultimately callsredirect()(which throws) and otherwise returnsPromise<void>, notPromise<AIEmailResponse>. This mismatch can lead to subtle runtime or type‑checking issues.To fix this, choose one of the following:
Promise<AIEmailResponse>, orPromise<AIEmailResponse | void>, so TS knows you may not return a payload when redirecting.return, call it withawait throwUnauthorizedGracefully();(so the action never actually returns), orthrowUnauthorizedGracefully()to return or throw a value that satisfiesAIEmailResponse(e.g. throw a typed exception or return a dummy response), ensuring all code paths adhere toAIEmailResponse.Files/locations to review:
throwUnauthorizedGracefullyreturn type