Skip to content

Commit 022593d

Browse files
Update packages/clerk-js/src/core/clerk.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 4845bf1 commit 022593d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/clerk-js/src/core/clerk.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,12 +1351,15 @@ export class Clerk implements ClerkInterface {
13511351
const newLastActiveOrganizationId = matchingOrganization?.organization.id || null;
13521352
const isPersonalWorkspace = newLastActiveOrganizationId === null;
13531353

1354-
// If a slug was explicitly provided but doesn't match any organization, throw an error
1355-
if (organizationIdOrSlug && !matchingOrganization) {
1356-
throw new Error(
1357-
`Unable to find organization with slug "${organizationIdOrSlug}". The user is not a member of this organization or it does not exist.`,
1358-
);
1359-
}
1354+
const INVALID_ORGANIZATION_SLUG_ERROR_CODE = 'invalid_organization_slug';
1355+
1356+
// If a slug was explicitly provided but doesn't match any organization, throw an error
1357+
if (organizationIdOrSlug && !matchingOrganization) {
1358+
throw new ClerkRuntimeError(
1359+
`Unable to find organization with slug "${organizationIdOrSlug}". The user is not a member of this organization or it does not exist.`,
1360+
{ code: INVALID_ORGANIZATION_SLUG_ERROR_CODE }
1361+
);
1362+
}
13601363

13611364
// Do not update in-memory to personal workspace if force organization selection is enabled
13621365
if (this.environment?.organizationSettings?.forceOrganizationSelection && isPersonalWorkspace) {

0 commit comments

Comments
 (0)