Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

559 B
Raw Blame
import { DatabaseError, Http, S3Error, StorageError } from "@cap/web-domain";
import { Effect, Schema } from "effect";

export const handleDomainError = <A, E, R>(e: Effect.Effect<A, E, R>) =>
	e.pipe(
		Effect.catchIf(
			(e) => Schema.is(DatabaseError)(e),
			() => new Http.InternalServerError({ cause: "database" }),
		),
		Effect.catchIf(
			(e) => Schema.is(S3Error)(e),
			() => new Http.InternalServerError({ cause: "s3" }),
		),
		Effect.catchIf(
			(e) => Schema.is(StorageError)(e),
			() => new Http.InternalServerError({ cause: "s3" }),
		),
	);