Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/builder/__tests__/create-first-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe("create-first-workspace", () => {

test("recognises only the listed codes, never prototype members", () => {
expect(isCreateChannelErrorCode("workspaceLimitReached")).toBe(true)
expect(isCreateChannelErrorCode("sessionExpired")).toBe(true)
expect(isCreateChannelErrorCode("toString")).toBe(false)
expect(isCreateChannelErrorCode(undefined)).toBe(false)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe("InstagramFacebookSelectPage", () => {
mockReadPendingAuth.mockResolvedValue(null)

await expect(InstagramFacebookSelectPage()).rejects.toThrow(
"redirect:/channels/create",
"redirect:/channels/create?error=sessionExpired",
)
expect(mockGetUserInstagramAccounts).not.toHaveBeenCalled()
})
Expand Down
5 changes: 4 additions & 1 deletion apps/builder/__tests__/instagram-select-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("InstagramSelectPage", () => {
mockReadPendingAuth.mockResolvedValue(null)

await expect(InstagramSelectPage()).rejects.toThrow(
"redirect:/channels/create",
"redirect:/channels/create?error=sessionExpired",
)
expect(mockGetInstagramAccount).not.toHaveBeenCalled()
})
Expand All @@ -85,5 +85,8 @@ describe("InstagramSelectPage", () => {
await expect(InstagramSelectPage()).rejects.toThrow(
"redirect:/channels/create",
)
expect(mockRedirect).not.toHaveBeenCalledWith(
"/channels/create?error=sessionExpired",
)
})
})
2 changes: 1 addition & 1 deletion apps/builder/__tests__/messenger-select-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe("MessengerSelectPage", () => {
mockReadPendingAuth.mockResolvedValue(null)

await expect(MessengerSelectPage()).rejects.toThrow(
"redirect:/channels/create",
"redirect:/channels/create?error=sessionExpired",
)
expect(mockGetUserPages).not.toHaveBeenCalled()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default async function InstagramFacebookSelectPage() {
const auth = await readPendingAuth(FB_INSTAGRAM_FACEBOOK_PENDING_AUTH_COOKIE)

if (!auth) {
redirect("/channels/create")
redirect("/channels/create?error=sessionExpired")
}

const accounts = await getUserInstagramAccounts(auth.userToken, auth.version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function InstagramSelectPage() {
const auth = await readPendingAuth(FB_INSTAGRAM_PENDING_AUTH_COOKIE)

if (!auth) {
redirect("/channels/create")
redirect("/channels/create?error=sessionExpired")
}

const account = await getInstagramAccount(auth.userToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default async function MessengerSelectPage() {
const pendingAuth = await readPendingAuth(FB_MESSENGER_PENDING_AUTH_COOKIE)

if (!pendingAuth) {
redirect("/channels/create")
redirect("/channels/create?error=sessionExpired")
}

const { pages, bmLookupFailed } = await getUserPages(
Expand Down
9 changes: 4 additions & 5 deletions apps/builder/src/lib/workspace/create-first-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import type { MessageKey } from "@/features/channel-connect/lib/message-key"
const CREATE_CHANNEL_ERROR_PARAM = "error"

/**
* Plan-limit failures the "create a workspace for the user's first channel"
* step can raise (`workspaceService.create`'s quota gates), keyed by
* `ChatbotXException.code` → the copy `/channels/create` shows for them. Any
* other error keeps propagating, so an unexpected failure is never dressed
* up as a plan limit.
* Known failures keyed by `ChatbotXException.code` or connect-flow error code
* → the copy `/channels/create` shows for them. Any other error keeps
* propagating, so an unexpected failure is never dressed up as a known error.
*/
export const CREATE_CHANNEL_ERROR_MESSAGE_KEYS = {
workspaceLimitReached: "channels.connectMany.reason.workspaceLimit",
trialExpired: "channels.connectMany.sessionError.trialExpired",
macLimitReached: "channels.connectMany.sessionError.macLimitReached",
sessionExpired: "channels.connectMany.sessionError.sessionExpired",
} as const satisfies Record<string, MessageKey>

export type CreateChannelErrorCode =
Expand Down