Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): return effects from error handlers

Richie McIlroyda8d8b0da87a
diff --git a/apps/web/app/api/mobile/[...route]/route.ts b/apps/web/app/api/mobile/[...route]/route.ts
index a5e263d7a..ba492f00c 100644
--- a/apps/web/app/api/mobile/[...route]/route.ts
+++ b/apps/web/app/api/mobile/[...route]/route.ts
@@ -1057,7 +1057,9 @@ const getPlayback = Effect.fn("Mobile.getPlayback")(function* (
const storage = yield* Storage;
const [video] = yield* videos.getByIdForViewing(videoId).pipe(
Effect.flatten,
- Effect.catchTag("NoSuchElementException", () => new Video.NotFoundError()),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new Video.NotFoundError()),
+ ),
);
if (video.ownerId !== user.id) {
diff --git a/apps/web/app/api/playlist/route.ts b/apps/web/app/api/playlist/route.ts
index e2af49d37..9eb7c42ca 100644
--- a/apps/web/app/api/playlist/route.ts
+++ b/apps/web/app/api/playlist/route.ts
@@ -298,7 +298,7 @@ const getPlaylistResponse = (
.pipe(
Effect.andThen(
Option.match({
- onNone: () => new HttpApiError.NotFound(),
+ onNone: () => Effect.fail(new HttpApiError.NotFound()),
onSome: (c) =>
HttpServerResponse.text(c).pipe(
HttpServerResponse.setHeaders({
@@ -319,7 +319,9 @@ const getPlaylistResponse = (
const enhancedAudioKey = `${video.ownerId}/${video.id}/enhanced-audio.mp3`;
return yield* bucket.getSignedObjectUrl(enhancedAudioKey).pipe(
Effect.map(HttpServerResponse.redirect),
- Effect.catchTag("StorageError", () => new HttpApiError.NotFound()),
+ Effect.catchTag("StorageError", () =>
+ Effect.fail(new HttpApiError.NotFound()),
+ ),
Effect.withSpan("fetchEnhancedAudio"),
);
}
diff --git a/packages/web-backend/src/Extension/Http.ts b/packages/web-backend/src/Extension/Http.ts
index c5ee0c564..87e6a5641 100644
--- a/packages/web-backend/src/Extension/Http.ts
+++ b/packages/web-backend/src/Extension/Http.ts
@@ -298,13 +298,11 @@ export const ExtensionHttpLive = HttpApiBuilder.group(
state: payload.state,
});
}).pipe(
- Effect.catchTag(
- "AuthKeyMintRateLimited",
- () => new HttpApiError.BadRequest(),
+ Effect.catchTag("AuthKeyMintRateLimited", () =>
+ Effect.fail(new HttpApiError.BadRequest()),
),
- Effect.catchTag(
- "UnknownException",
- () => new Http.InternalServerError({ cause: "unknown" }),
+ Effect.catchTag("UnknownException", () =>
+ Effect.fail(new Http.InternalServerError({ cause: "unknown" })),
),
handleDomainError,
),
@@ -322,7 +320,9 @@ export const ExtensionHttpLive = HttpApiBuilder.group(
return { success: true };
}).pipe(
- Effect.catchTag("ParseError", () => new HttpApiError.BadRequest()),
+ Effect.catchTag("ParseError", () =>
+ Effect.fail(new HttpApiError.BadRequest()),
+ ),
handleDomainError,
),
)
diff --git a/packages/web-backend/src/Loom/Http.ts b/packages/web-backend/src/Loom/Http.ts
index 0a6935b0a..ee1009ed4 100644
--- a/packages/web-backend/src/Loom/Http.ts
+++ b/packages/web-backend/src/Loom/Http.ts
@@ -17,7 +17,9 @@ export const LoomHttpLive = HttpApiBuilder.group(
return handlers.handle("importVideo", ({ payload }) =>
Effect.gen(function* () {
const workflows = yield* _workflows.pipe(
- Effect.catchAll(() => new HttpApiError.ServiceUnavailable()),
+ Effect.catchAll(() =>
+ Effect.fail(new HttpApiError.ServiceUnavailable()),
+ ),
);
const user = yield* CurrentUser;
@@ -30,9 +32,8 @@ export const LoomHttpLive = HttpApiBuilder.group(
loom: payload.loom,
})
.pipe(
- Effect.catchTag(
- "RpcClientError",
- () => new Http.InternalServerError({ cause: "unknown" }),
+ Effect.catchTag("RpcClientError", () =>
+ Effect.fail(new Http.InternalServerError({ cause: "unknown" })),
),
);
diff --git a/packages/web-backend/src/Loom/ImportVideo.ts b/packages/web-backend/src/Loom/ImportVideo.ts
index 3d5ba9101..917a54bda 100644
--- a/packages/web-backend/src/Loom/ImportVideo.ts
+++ b/packages/web-backend/src/Loom/ImportVideo.ts
@@ -117,16 +117,19 @@ export const LoomImportVideoLive = Loom.ImportVideo.toLayer(
const resp = yield* http
.get(payload.loom.video.downloadUrl)
.pipe(
- Effect.catchAll((cause) => new Loom.ExternalLoomError({ cause })),
+ Effect.catchAll((cause) =>
+ Effect.fail(new Loom.ExternalLoomError({ cause })),
+ ),
);
const contentLength = yield* Headers.get(
resp.headers,
"content-length",
).pipe(
Option.map((v) => Number(v)),
- Effect.catchTag(
- "NoSuchElementException",
- () => new Loom.VideoInvalidError({ cause: "InvalidContentLength" }),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(
+ new Loom.VideoInvalidError({ cause: "InvalidContentLength" }),
+ ),
),
);
yield* Effect.log(`Downloading ${contentLength} bytes`);
diff --git a/packages/web-backend/src/Rpcs.ts b/packages/web-backend/src/Rpcs.ts
index 0b4fb0632..c3cb95cd1 100644
--- a/packages/web-backend/src/Rpcs.ts
+++ b/packages/web-backend/src/Rpcs.ts
@@ -27,10 +27,12 @@ export const RpcAuthMiddlewareLive = Layer.effect(
return RpcAuthMiddleware.of(() =>
getCurrentUser.pipe(
Effect.provideService(Database, database),
- Effect.catchAll(() => new InternalError({ type: "database" })),
+ Effect.catchAll(() =>
+ Effect.fail(new InternalError({ type: "database" })),
+ ),
Effect.flatMap(
Option.match({
- onNone: () => new UnauthenticatedError(),
+ onNone: () => Effect.fail(new UnauthenticatedError()),
onSome: (user) => Effect.succeed(makeCurrentUser(user)),
}),
),
diff --git a/packages/web-backend/src/S3Buckets/S3BucketAccess.ts b/packages/web-backend/src/S3Buckets/S3BucketAccess.ts
index 106e98985..2b10e34d8 100644
--- a/packages/web-backend/src/S3Buckets/S3BucketAccess.ts
+++ b/packages/web-backend/src/S3Buckets/S3BucketAccess.ts
@@ -36,7 +36,9 @@ const wrapS3Promise = <T>(
),
);
}).pipe(
- Effect.catchTag("UnknownException", (cause) => new S3Error({ cause })),
+ Effect.catchTag("UnknownException", (cause) =>
+ Effect.fail(new S3Error({ cause })),
+ ),
);
export const createS3BucketAccess = Effect.gen(function* () {