Skip to content

Commit 15f3a3b

Browse files
committed
organize imports and try catch server fn
1 parent 9dfb9fa commit 15f3a3b

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

app/routes/success.tsx

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { useRealtimeRun } from "@trigger.dev/react-hooks";
1010
import { runs, auth as triggerAuth } from "@trigger.dev/sdk/v3";
1111
import { CheckCircleIcon, Loader2Icon, XCircleIcon } from "lucide-react";
1212
import { useEffect, useState } from "react";
13-
import { z } from "zod";
1413
import Confetti from "react-confetti-boom";
14+
import { z } from "zod";
1515

1616
export const Route = createFileRoute("/success")({
1717
component: RouteComponent,
@@ -180,33 +180,38 @@ function RouteComponent() {
180180
const getPolarEventHandlerForUserServerFn = createServerFn({
181181
method: "POST",
182182
}).handler(async () => {
183-
const { userId } = await getAuth(getWebRequest()!);
183+
try {
184+
const { userId } = await getAuth(getWebRequest()!);
184185

185-
if (!userId) {
186-
throw redirect({ to: "/" });
187-
}
186+
if (!userId) {
187+
throw redirect({ to: "/" });
188+
}
188189

189-
const runningTasks = await runs.list({ tag: userId });
190+
const runningTasks = await runs.list({ tag: userId });
190191

191-
const polarEventHandler = runningTasks.data.find(
192-
(t) => t.taskIdentifier === "polar-event-handler"
193-
);
192+
const polarEventHandler = runningTasks.data.find(
193+
(t) => t.taskIdentifier === "polar-event-handler"
194+
);
194195

195-
if (!polarEventHandler) {
196-
throw redirect({ to: "/videos" });
197-
}
196+
if (!polarEventHandler) {
197+
throw redirect({ to: "/videos" });
198+
}
198199

199-
const accessToken = await triggerAuth.createPublicToken({
200-
expirationTime: 1000 * 60 * 5,
201-
scopes: {
202-
read: {
203-
tags: [userId],
200+
const accessToken = await triggerAuth.createPublicToken({
201+
expirationTime: 1000 * 60 * 5,
202+
scopes: {
203+
read: {
204+
tags: [userId],
205+
},
204206
},
205-
},
206-
});
207-
208-
return {
209-
token: accessToken,
210-
runId: polarEventHandler.id,
211-
};
207+
});
208+
209+
return {
210+
token: accessToken,
211+
runId: polarEventHandler.id,
212+
};
213+
} catch (error) {
214+
console.error("Error in getPolarEventHandlerForUserServerFn:", error);
215+
throw redirect({ to: "/videos" });
216+
}
212217
});

0 commit comments

Comments
 (0)