Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(organisations): map soft delete RPC errors for policy and S3

Richie McIlroy4df4e403bfff
diff --git a/packages/web-backend/src/Organisations/OrganisationsRpcs.ts b/packages/web-backend/src/Organisations/OrganisationsRpcs.ts
index 899139e26..5aee40602 100644
--- a/packages/web-backend/src/Organisations/OrganisationsRpcs.ts
+++ b/packages/web-backend/src/Organisations/OrganisationsRpcs.ts
@@ -1,7 +1,24 @@
-import { InternalError, Organisation } from "@cap/web-domain";
-import { Effect } from "effect";
+import {
+ DatabaseError,
+ InternalError,
+ Organisation,
+ Policy,
+ S3Error,
+} from "@cap/web-domain";
+import { Effect, Schema } from "effect";
import { Organisations } from ".";
+const mapSoftDeleteError = (
+ error: unknown,
+): Organisation.NotFoundError | Policy.PolicyDeniedError | InternalError => {
+ if (Schema.is(Organisation.NotFoundError)(error)) return error;
+ if (Schema.is(Policy.PolicyDeniedError)(error)) return error;
+ if (Schema.is(DatabaseError)(error))
+ return new InternalError({ type: "database" });
+ if (Schema.is(S3Error)(error)) return new InternalError({ type: "s3" });
+ return new InternalError({ type: "unknown" });
+};
+
export const OrganisationsRpcsLive = Organisation.OrganisationRpcs.toLayer(
Effect.gen(function* () {
const orgs = yield* Organisations;
@@ -15,11 +32,11 @@ export const OrganisationsRpcsLive = Organisation.OrganisationRpcs.toLayer(
}),
),
OrganisationSoftDelete: (data) =>
- orgs.softDelete(data.id).pipe(
- Effect.catchTags({
- DatabaseError: () => new InternalError({ type: "database" }),
- }),
- ),
+ orgs
+ .softDelete(data.id)
+ .pipe(
+ Effect.catchAll((error) => Effect.fail(mapSoftDeleteError(error))),
+ ),
};
}),
);