Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3interface CloudWaitlistJoiner {
4 readonly join: (input: { emailAddress: string }) => Promise<{
5 readonly error: { readonly code: string } | null;
6 }>;
7}
8
9export class CloudWaitlistJoinRejectedError extends Schema.TaggedErrorClass<CloudWaitlistJoinRejectedError>()(
10 "CloudWaitlistJoinRejectedError",
11 {
12 code: Schema.String,
13 cause: Schema.Defect(),
14 },
15) {
16 override get message(): string {
17 return `Cloud waitlist enrollment was rejected with code "${this.code}".`;
18 }
19}
20
21export class CloudWaitlistJoinRequestError extends Schema.TaggedErrorClass<CloudWaitlistJoinRequestError>()(
22 "CloudWaitlistJoinRequestError",
23 {
24 cause: Schema.Defect(),
25 },
26) {
27 override get message(): string {
28 return "Cloud waitlist enrollment request failed.";
29 }
30}
31
32export async function joinCloudWaitlist(
33 waitlist: CloudWaitlistJoiner,
34 emailAddress: string,
35): Promise<void> {
36 const result = await waitlist.join({ emailAddress }).catch((cause) => {
37 throw new CloudWaitlistJoinRequestError({ cause });
38 });
39
40 if (result.error) {
41 throw new CloudWaitlistJoinRejectedError({
42 code: result.error.code,
43 cause: result.error,
44 });
45 }
46}