Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): fail mapped effects

Richie McIlroya97363760375
diff --git a/apps/web/app/api/mobile/[...route]/route.ts b/apps/web/app/api/mobile/[...route]/route.ts
index ba492f00c..968bc73be 100644
--- a/apps/web/app/api/mobile/[...route]/route.ts
+++ b/apps/web/app/api/mobile/[...route]/route.ts
@@ -277,14 +277,15 @@ const toMobileCapSummary = (
const withMappedErrors = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
effect.pipe(
Effect.catchTags({
- DatabaseError: () => new HttpApiError.InternalServerError(),
- NoSuchElementException: () => new HttpApiError.NotFound(),
- PolicyDenied: () => new HttpApiError.Forbidden(),
- S3Error: () => new HttpApiError.InternalServerError(),
- StorageError: () => new HttpApiError.InternalServerError(),
- UnknownException: () => new HttpApiError.InternalServerError(),
- VerifyVideoPasswordError: () => new HttpApiError.Forbidden(),
- VideoNotFoundError: () => new HttpApiError.NotFound(),
+ DatabaseError: () => Effect.fail(new HttpApiError.InternalServerError()),
+ NoSuchElementException: () => Effect.fail(new HttpApiError.NotFound()),
+ PolicyDenied: () => Effect.fail(new HttpApiError.Forbidden()),
+ S3Error: () => Effect.fail(new HttpApiError.InternalServerError()),
+ StorageError: () => Effect.fail(new HttpApiError.InternalServerError()),
+ UnknownException: () =>
+ Effect.fail(new HttpApiError.InternalServerError()),
+ VerifyVideoPasswordError: () => Effect.fail(new HttpApiError.Forbidden()),
+ VideoNotFoundError: () => Effect.fail(new HttpApiError.NotFound()),
}),
);
diff --git a/apps/web/app/api/playlist/route.ts b/apps/web/app/api/playlist/route.ts
index 9eb7c42ca..e6a3f9b32 100644
--- a/apps/web/app/api/playlist/route.ts
+++ b/apps/web/app/api/playlist/route.ts
@@ -67,9 +67,8 @@ const ApiLive = HttpApiBuilder.api(Api).pipe(
.getByIdForViewing(urlParams.videoId)
.pipe(
Effect.flatten,
- Effect.catchTag(
- "NoSuchElementException",
- () => new HttpApiError.NotFound(),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new HttpApiError.NotFound()),
),
);
@@ -78,11 +77,15 @@ const ApiLive = HttpApiBuilder.api(Api).pipe(
provideOptionalAuth,
Effect.tapErrorCause(Effect.logError),
Effect.catchTags({
- VerifyVideoPasswordError: () => new HttpApiError.Forbidden(),
- PolicyDenied: () => new HttpApiError.Unauthorized(),
- DatabaseError: () => new HttpApiError.InternalServerError(),
- StorageError: () => new HttpApiError.InternalServerError(),
- UnknownException: () => new HttpApiError.InternalServerError(),
+ VerifyVideoPasswordError: () =>
+ Effect.fail(new HttpApiError.Forbidden()),
+ PolicyDenied: () => Effect.fail(new HttpApiError.Unauthorized()),
+ DatabaseError: () =>
+ Effect.fail(new HttpApiError.InternalServerError()),
+ StorageError: () =>
+ Effect.fail(new HttpApiError.InternalServerError()),
+ UnknownException: () =>
+ Effect.fail(new HttpApiError.InternalServerError()),
}),
Effect.provideService(Storage, storage),
),
diff --git a/apps/web/app/api/video/delete/route.ts b/apps/web/app/api/video/delete/route.ts
index b370e7fbb..f0e709ae0 100644
--- a/apps/web/app/api/video/delete/route.ts
+++ b/apps/web/app/api/video/delete/route.ts
@@ -29,15 +29,20 @@ const ApiLive = HttpApiBuilder.api(Api).pipe(
return handlers.handle("deleteVideo", ({ urlParams }) =>
videos.delete(urlParams.videoId).pipe(
Effect.catchTags({
- VideoNotFoundError: () => new HttpApiError.NotFound(),
- PolicyDenied: () => new HttpApiError.Unauthorized(),
+ VideoNotFoundError: () =>
+ Effect.fail(new HttpApiError.NotFound()),
+ PolicyDenied: () => Effect.fail(new HttpApiError.Unauthorized()),
DatabaseError: (e) =>
Effect.logError(e).pipe(
- Effect.andThen(() => new HttpApiError.InternalServerError()),
+ Effect.andThen(() =>
+ Effect.fail(new HttpApiError.InternalServerError()),
+ ),
),
StorageError: (e) =>
Effect.logError(e).pipe(
- Effect.andThen(() => new HttpApiError.InternalServerError()),
+ Effect.andThen(() =>
+ Effect.fail(new HttpApiError.InternalServerError()),
+ ),
),
}),
),
diff --git a/packages/web-backend/src/Auth.ts b/packages/web-backend/src/Auth.ts
index aec0188ae..356fffdd3 100644
--- a/packages/web-backend/src/Auth.ts
+++ b/packages/web-backend/src/Auth.ts
@@ -87,17 +87,18 @@ export const HttpAuthMiddlewareLive = Layer.effect(
return yield* user.pipe(
Option.map(makeCurrentUser),
- Effect.catchTag(
- "NoSuchElementException",
- () => new HttpApiError.Unauthorized(),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new HttpApiError.Unauthorized()),
),
);
}).pipe(
Effect.provideService(Database, database),
Effect.catchTags({
- UnknownException: () => new HttpApiError.InternalServerError(),
- DatabaseError: () => new HttpApiError.InternalServerError(),
- ParseError: () => new HttpApiError.BadRequest(),
+ UnknownException: () =>
+ Effect.fail(new HttpApiError.InternalServerError()),
+ DatabaseError: () =>
+ Effect.fail(new HttpApiError.InternalServerError()),
+ ParseError: () => Effect.fail(new HttpApiError.BadRequest()),
}),
),
);
diff --git a/packages/web-backend/src/Extension/Http.ts b/packages/web-backend/src/Extension/Http.ts
index 87e6a5641..f920710f8 100644
--- a/packages/web-backend/src/Extension/Http.ts
+++ b/packages/web-backend/src/Extension/Http.ts
@@ -241,9 +241,8 @@ export const ExtensionHttpLive = HttpApiBuilder.group(
state: urlParams.state,
});
}).pipe(
- Effect.catchTag(
- "UnknownException",
- () => new Http.InternalServerError({ cause: "unknown" }),
+ Effect.catchTag("UnknownException", () =>
+ Effect.fail(new Http.InternalServerError({ cause: "unknown" })),
),
handleDomainError,
),
@@ -359,23 +358,27 @@ export const ExtensionHttpLive = HttpApiBuilder.group(
)
.handle("createInstantRecording", ({ payload }) =>
videos.createInstantRecording(payload).pipe(
- Effect.catchTag("PolicyDenied", (error) => error),
+ Effect.catchTag("PolicyDenied", (error) => Effect.fail(error)),
handleDomainError,
),
)
.handle("updateInstantRecordingProgress", ({ payload }) =>
videos.updateUploadProgress(payload).pipe(
Effect.map((success) => ({ success })),
- Effect.catchTag("VideoNotFoundError", (error) => error),
- Effect.catchTag("PolicyDenied", (error) => error),
+ Effect.catchTag("VideoNotFoundError", (error) =>
+ Effect.fail(error),
+ ),
+ Effect.catchTag("PolicyDenied", (error) => Effect.fail(error)),
handleDomainError,
),
)
.handle("deleteInstantRecording", ({ path }) =>
videos.delete(path.videoId).pipe(
Effect.as({ success: true }),
- Effect.catchTag("VideoNotFoundError", (error) => error),
- Effect.catchTag("PolicyDenied", (error) => error),
+ Effect.catchTag("VideoNotFoundError", (error) =>
+ Effect.fail(error),
+ ),
+ Effect.catchTag("PolicyDenied", (error) => Effect.fail(error)),
handleDomainError,
),
);
diff --git a/packages/web-backend/src/Folders/FoldersPolicy.ts b/packages/web-backend/src/Folders/FoldersPolicy.ts
index 9576c931c..80a39beed 100644
--- a/packages/web-backend/src/Folders/FoldersPolicy.ts
+++ b/packages/web-backend/src/Folders/FoldersPolicy.ts
@@ -36,9 +36,8 @@ export class FoldersPolicy extends Effect.Service<FoldersPolicy>()(
Policy.policy((user) =>
Effect.gen(function* () {
const folder = yield* (yield* repo.getById(id)).pipe(
- Effect.catchTag(
- "NoSuchElementException",
- () => new Policy.PolicyDeniedError(),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new Policy.PolicyDeniedError()),
),
);
diff --git a/packages/web-backend/src/Folders/FoldersRpcs.ts b/packages/web-backend/src/Folders/FoldersRpcs.ts
index 7a1882ba1..1b129f4d3 100644
--- a/packages/web-backend/src/Folders/FoldersRpcs.ts
+++ b/packages/web-backend/src/Folders/FoldersRpcs.ts
@@ -12,9 +12,8 @@ export const FolderRpcsLive = Folder.FolderRpcs.toLayer(
folders
.delete(folderId)
.pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
),
@@ -22,9 +21,8 @@ export const FolderRpcsLive = Folder.FolderRpcs.toLayer(
folders
.create(data)
.pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
),
@@ -32,9 +30,8 @@ export const FolderRpcsLive = Folder.FolderRpcs.toLayer(
folders
.update(data)
.pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
),
};
diff --git a/packages/web-backend/src/Folders/index.ts b/packages/web-backend/src/Folders/index.ts
index bd2f915e9..941e72992 100644
--- a/packages/web-backend/src/Folders/index.ts
+++ b/packages/web-backend/src/Folders/index.ts
@@ -129,9 +129,8 @@ export class Folders extends Effect.Service<Folders>()("Folders", {
.pipe(
Policy.withPolicy(policy.canEdit(parentId)),
Effect.flatMap(
- Effect.catchTag(
- "NoSuchElementException",
- () => new Folder.NotFoundError(),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new Folder.NotFoundError()),
),
),
);
@@ -172,9 +171,8 @@ export class Folders extends Effect.Service<Folders>()("Folders", {
const folder = yield* (yield* repo
.getById(data.id)
.pipe(Policy.withPolicy(policy.canEdit(data.id)))).pipe(
- Effect.catchTag(
- "NoSuchElementException",
- () => new Folder.NotFoundError(),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new Folder.NotFoundError()),
),
);
@@ -212,9 +210,8 @@ export class Folders extends Effect.Service<Folders>()("Folders", {
.pipe(
Policy.withPolicy(policy.canEdit(parentId)),
Effect.flatMap(
- Effect.catchTag(
- "NoSuchElementException",
- () => new Folder.ParentNotFoundError(),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new Folder.ParentNotFoundError()),
),
),
);
diff --git a/packages/web-backend/src/Organisations/OrganisationsRpcs.ts b/packages/web-backend/src/Organisations/OrganisationsRpcs.ts
index 5aee40602..577ca57c4 100644
--- a/packages/web-backend/src/Organisations/OrganisationsRpcs.ts
+++ b/packages/web-backend/src/Organisations/OrganisationsRpcs.ts
@@ -27,8 +27,9 @@ export const OrganisationsRpcsLive = Organisation.OrganisationRpcs.toLayer(
OrganisationUpdate: (data) =>
orgs.update(data).pipe(
Effect.catchTags({
- DatabaseError: () => new InternalError({ type: "database" }),
- S3Error: () => new InternalError({ type: "s3" }),
+ DatabaseError: () =>
+ Effect.fail(new InternalError({ type: "database" })),
+ S3Error: () => Effect.fail(new InternalError({ type: "s3" })),
}),
),
OrganisationSoftDelete: (data) =>
diff --git a/packages/web-backend/src/Organisations/index.ts b/packages/web-backend/src/Organisations/index.ts
index 9c68e1baf..4fc624fe1 100644
--- a/packages/web-backend/src/Organisations/index.ts
+++ b/packages/web-backend/src/Organisations/index.ts
@@ -47,9 +47,8 @@ export class Organisations extends Effect.Service<Organisations>()(
)
.pipe(
Effect.flatMap(EffectArray.get(0)),
- Effect.catchTag(
- "NoSuchElementException",
- () => new Organisation.NotFoundError(),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new Organisation.NotFoundError()),
),
Policy.withPolicy(policy.isAdminOrOwner(payload.id)),
);
@@ -87,9 +86,8 @@ export class Organisations extends Effect.Service<Organisations>()(
)
.pipe(
Effect.flatMap(EffectArray.get(0)),
- Effect.catchTag(
- "NoSuchElementException",
- () => new Organisation.NotFoundError(),
+ Effect.catchTag("NoSuchElementException", () =>
+ Effect.fail(new Organisation.NotFoundError()),
),
);
diff --git a/packages/web-backend/src/Users/UsersRpcs.ts b/packages/web-backend/src/Users/UsersRpcs.ts
index 102db93b5..1e0291d55 100644
--- a/packages/web-backend/src/Users/UsersRpcs.ts
+++ b/packages/web-backend/src/Users/UsersRpcs.ts
@@ -37,16 +37,16 @@ export const UsersRpcsLive = User.UserRpcs.toLayer(
return { step: "skipToDashboard" as const, data: undefined };
}
}).pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
),
UserUpdate: (data) =>
users.update(data).pipe(
Effect.catchTags({
- DatabaseError: () => new InternalError({ type: "database" }),
- S3Error: () => new InternalError({ type: "s3" }),
+ DatabaseError: () =>
+ Effect.fail(new InternalError({ type: "database" })),
+ S3Error: () => Effect.fail(new InternalError({ type: "s3" })),
}),
),
};
diff --git a/packages/web-backend/src/Videos/VideosRpcs.ts b/packages/web-backend/src/Videos/VideosRpcs.ts
index 8c6a9b169..6f2d8db2e 100644
--- a/packages/web-backend/src/Videos/VideosRpcs.ts
+++ b/packages/web-backend/src/Videos/VideosRpcs.ts
@@ -11,50 +11,42 @@ export const VideosRpcsLive = Video.VideoRpcs.toLayer(
return {
VideoDelete: (videoId) =>
videos.delete(videoId).pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
- Effect.catchTag(
- "StorageError",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("StorageError", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
),
VideoDuplicate: (videoId) =>
videos.duplicate(videoId).pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
- Effect.catchTag(
- "StorageError",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("StorageError", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
),
GetUploadProgress: (videoId) =>
videos.getUploadProgress(videoId).pipe(
provideOptionalAuth,
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
- Effect.catchTag(
- "UnknownException",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("UnknownException", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
),
VideoInstantCreate: (input) =>
videos.createInstantRecording(input).pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
- Effect.catchTag(
- "StorageError",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("StorageError", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
),
@@ -62,26 +54,22 @@ export const VideosRpcsLive = Video.VideoRpcs.toLayer(
videos
.updateUploadProgress(input)
.pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
),
VideoGetDownloadInfo: (videoId) =>
videos.getDownloadInfo(videoId).pipe(
provideOptionalAuth,
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
- Effect.catchTag(
- "UnknownException",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("UnknownException", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
- Effect.catchTag(
- "StorageError",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("StorageError", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
),
@@ -89,13 +77,11 @@ export const VideosRpcsLive = Video.VideoRpcs.toLayer(
Effect.all(
videoIds.map((id) =>
videos.getThumbnailURL(id).pipe(
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
- Effect.catchTag(
- "StorageError",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("StorageError", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
Effect.matchEffect({
onSuccess: (v) => Effect.succeed(Exit.succeed(v)),
@@ -110,13 +96,11 @@ export const VideosRpcsLive = Video.VideoRpcs.toLayer(
{ concurrency: 10 },
).pipe(
provideOptionalAuth,
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
- Effect.catchTag(
- "UnknownException",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("UnknownException", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
),
@@ -147,13 +131,11 @@ export const VideosRpcsLive = Video.VideoRpcs.toLayer(
>[],
),
provideOptionalAuth,
- Effect.catchTag(
- "DatabaseError",
- () => new InternalError({ type: "database" }),
+ Effect.catchTag("DatabaseError", () =>
+ Effect.fail(new InternalError({ type: "database" })),
),
- Effect.catchTag(
- "UnknownException",
- () => new InternalError({ type: "unknown" }),
+ Effect.catchTag("UnknownException", () =>
+ Effect.fail(new InternalError({ type: "unknown" })),
),
),
};