Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): return clean 500 when transcribe status check throws

Richie McIlroyf05789e1f336
diff --git a/apps/web/app/api/video/transcribe/status/route.ts b/apps/web/app/api/video/transcribe/status/route.ts
index 45091fa7d..1e84b9093 100644
--- a/apps/web/app/api/video/transcribe/status/route.ts
+++ b/apps/web/app/api/video/transcribe/status/route.ts
@@ -11,35 +11,51 @@ import * as EffectRuntime from "@/lib/server";
export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) {
- const user = await getCurrentUser();
- const url = new URL(request.url);
- const videoId = url.searchParams.get("videoId") as Video.VideoId;
+ try {
+ const user = await getCurrentUser();
+ const url = new URL(request.url);
+ const videoId = url.searchParams.get("videoId") as Video.VideoId;
- if (!user) {
- return Response.json({ auth: false }, { status: 401 });
- }
+ if (!user) {
+ return Response.json({ auth: false }, { status: 401 });
+ }
- if (!videoId) {
- return Response.json(
- { error: true, message: "videoId not supplied" },
- { status: 400 },
- );
- }
+ if (!videoId) {
+ return Response.json(
+ { error: true, message: "videoId not supplied" },
+ { status: 400 },
+ );
+ }
+
+ const exit = await Effect.gen(function* () {
+ const videosPolicy = yield* VideosPolicy;
- const exit = await Effect.gen(function* () {
- const videosPolicy = yield* VideosPolicy;
+ return yield* Effect.promise(() =>
+ db().select().from(videos).where(eq(videos.id, videoId)),
+ ).pipe(Policy.withPublicPolicy(videosPolicy.canView(videoId)));
+ }).pipe(provideOptionalAuth, EffectRuntime.runPromiseExit);
- return yield* Effect.promise(() =>
- db().select().from(videos).where(eq(videos.id, videoId)),
- ).pipe(Policy.withPublicPolicy(videosPolicy.canView(videoId)));
- }).pipe(provideOptionalAuth, EffectRuntime.runPromiseExit);
+ if (Exit.isFailure(exit)) {
+ const error = Option.getOrUndefined(Cause.failureOption(exit.cause));
+ if (
+ Schema.is(Policy.PolicyDeniedError)(error) ||
+ Schema.is(Video.VerifyVideoPasswordError)(error)
+ ) {
+ return Response.json(
+ { error: true, message: "Video does not exist" },
+ { status: 404 },
+ );
+ }
- if (Exit.isFailure(exit)) {
- const error = Option.getOrUndefined(Cause.failureOption(exit.cause));
- if (
- Schema.is(Policy.PolicyDeniedError)(error) ||
- Schema.is(Video.VerifyVideoPasswordError)(error)
- ) {
+ return Response.json(
+ { error: true, message: "An unexpected error occurred" },
+ { status: 500 },
+ );
+ }
+
+ const video = exit.value;
+
+ if (video.length === 0 || !video[0]) {
return Response.json(
{ error: true, message: "Video does not exist" },
{ status: 404 },
@@ -47,22 +63,17 @@ export async function GET(request: NextRequest) {
}
return Response.json(
- { error: true, message: "An unexpected error occurred" },
- { status: 500 },
+ { transcriptionStatus: video[0].transcriptionStatus },
+ { status: 200 },
+ );
+ } catch (error) {
+ console.error(
+ "[transcribe status] Unexpected error checking video access:",
+ error,
);
- }
-
- const video = exit.value;
-
- if (video.length === 0 || !video[0]) {
return Response.json(
- { error: true, message: "Video does not exist" },
- { status: 404 },
+ { error: true, message: "An unexpected error occurred" },
+ { status: 500 },
);
}
-
- return Response.json(
- { transcriptionStatus: video[0].transcriptionStatus },
- { status: 200 },
- );
}