Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
[codex] Structure mobile waitlist enrollment failures (#3446)
Julius Marminge28e7c9ae17af
diff --git a/apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsx b/apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsxindex 77b48d44b..4d5b57033 100644--- a/apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsx+++ b/apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsx@@ -4,6 +4,7 @@ import { useState } from "react";import { MOBILE_TYPOGRAPHY } from "../../lib/typography";import { useThemeColor } from "../../lib/useThemeColor";+import { CloudWaitlistJoinRejectedError, joinCloudWaitlist } from "./cloudWaitlistJoin";export function CloudWaitlistEnrollment(props: { readonly onSignIn: () => void }) {const { errors, fetchStatus, waitlist } = useWaitlist();@@ -21,12 +22,14 @@ export function CloudWaitlistEnrollment(props: { readonly onSignIn: () => void }setRequestError(null);try {- const { error } = await waitlist.join({ emailAddress: normalizedEmailAddress });- if (error) {- setRequestError("Could not join the waitlist. Check your email address and try again.");- }- } catch {- setRequestError("Could not join the waitlist. Check your connection and try again.");+ await joinCloudWaitlist(waitlist, normalizedEmailAddress);+ } catch (error) {+ console.error(error);+ setRequestError(+ error instanceof CloudWaitlistJoinRejectedError+ ? "Could not join the waitlist. Check your email address and try again."+ : "Could not join the waitlist. Check your connection and try again.",+ );}};diff --git a/apps/mobile/src/features/cloud/cloudWaitlistJoin.test.ts b/apps/mobile/src/features/cloud/cloudWaitlistJoin.test.tsnew file mode 100644index 000000000..582cb40ff--- /dev/null+++ b/apps/mobile/src/features/cloud/cloudWaitlistJoin.test.ts@@ -0,0 +1,48 @@+import { describe, expect, it, vi } from "vite-plus/test";++import {+ CloudWaitlistJoinRejectedError,+ CloudWaitlistJoinRequestError,+ joinCloudWaitlist,+} from "./cloudWaitlistJoin";++describe("joinCloudWaitlist", () => {+ it("submits the provided email address", async () => {+ const join = vi.fn().mockResolvedValue({ error: null });++ await joinCloudWaitlist({ join }, "[email protected]");++ expect(join).toHaveBeenCalledExactlyOnceWith({ emailAddress: "[email protected]" });+ });++ it("preserves Clerk rejection details without exposing the email address", async () => {+ const cause = Object.assign(new Error("The enrollment was rejected."), {+ code: "form_identifier_invalid",+ });+ const join = vi.fn().mockResolvedValue({ error: cause });++ const failure = await joinCloudWaitlist({ join }, "[email protected]").catch(+ (error: unknown) => error,+ );++ expect(failure).toBeInstanceOf(CloudWaitlistJoinRejectedError);+ expect(failure).toMatchObject({+ code: "form_identifier_invalid",+ cause,+ });+ expect(String(failure)).not.toContain("[email protected]");+ });++ it("distinguishes request failures from rejected enrollments", async () => {+ const cause = new Error("network unavailable");+ const join = vi.fn().mockRejectedValue(cause);++ const failure = await joinCloudWaitlist({ join }, "[email protected]").catch(+ (error: unknown) => error,+ );++ expect(failure).toBeInstanceOf(CloudWaitlistJoinRequestError);+ expect(failure).toMatchObject({ cause });+ expect(failure).not.toBeInstanceOf(CloudWaitlistJoinRejectedError);+ });+});diff --git a/apps/mobile/src/features/cloud/cloudWaitlistJoin.ts b/apps/mobile/src/features/cloud/cloudWaitlistJoin.tsnew file mode 100644index 000000000..4a467a19e--- /dev/null+++ b/apps/mobile/src/features/cloud/cloudWaitlistJoin.ts@@ -0,0 +1,46 @@+import * as Schema from "effect/Schema";++interface CloudWaitlistJoiner {+ readonly join: (input: { emailAddress: string }) => Promise<{+ readonly error: { readonly code: string } | null;+ }>;+}++export class CloudWaitlistJoinRejectedError extends Schema.TaggedErrorClass<CloudWaitlistJoinRejectedError>()(+ "CloudWaitlistJoinRejectedError",+ {+ code: Schema.String,+ cause: Schema.Defect(),+ },+) {+ override get message(): string {+ return `Cloud waitlist enrollment was rejected with code "${this.code}".`;+ }+}++export class CloudWaitlistJoinRequestError extends Schema.TaggedErrorClass<CloudWaitlistJoinRequestError>()(+ "CloudWaitlistJoinRequestError",+ {+ cause: Schema.Defect(),+ },+) {+ override get message(): string {+ return "Cloud waitlist enrollment request failed.";+ }+}++export async function joinCloudWaitlist(+ waitlist: CloudWaitlistJoiner,+ emailAddress: string,+): Promise<void> {+ const result = await waitlist.join({ emailAddress }).catch((cause) => {+ throw new CloudWaitlistJoinRequestError({ cause });+ });++ if (result.error) {+ throw new CloudWaitlistJoinRejectedError({+ code: result.error.code,+ cause: result.error,+ });+ }+}