Skip to content

Commit 45cbaea

Browse files
committed
fix(javascript): improve error handling in deriveOrganizationHandleFromBaseUrl function
1 parent b837bd3 commit 45cbaea

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

packages/javascript/src/utils/deriveOrganizationHandleFromBaseUrl.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,35 @@ const deriveOrganizationHandleFromBaseUrl = (baseUrl?: string): string => {
6969
);
7070
}
7171

72-
// Check if the hostname matches the Asgardeo pattern: *.asgardeo.io
73-
const hostname = parsedUrl.hostname.toLowerCase();
74-
if (!hostname.endsWith('.asgardeo.io')) {
75-
throw new AsgardeoRuntimeError(
76-
'Organization handle is required since a custom domain is configured.',
77-
'javascript-deriveOrganizationHandleFromBaseUrl-CustomDomainError-001',
78-
'javascript',
79-
'The provided base URL uses a custom domain. Please provide the organizationHandle explicitly in the configuration.',
80-
);
81-
}
82-
8372
// Extract the organization handle from the path pattern: /t/{orgHandle}
84-
const pathSegments = parsedUrl.pathname.split('/').filter(segment => segment.length > 0);
73+
const pathSegments = parsedUrl.pathname?.split('/')?.filter(segment => segment?.length > 0);
8574

8675
if (pathSegments.length < 2 || pathSegments[0] !== 't') {
87-
throw new AsgardeoRuntimeError(
88-
'Organization handle is required since a custom domain is configured.',
89-
'javascript-deriveOrganizationHandleFromBaseUrl-CustomDomainError-002',
90-
'javascript',
91-
'The provided base URL does not follow the expected Asgardeo URL pattern (/t/{orgHandle}). Please provide the organizationHandle explicitly in the configuration.',
76+
console.warn(
77+
new AsgardeoRuntimeError(
78+
'Organization handle is required since a custom domain is configured.',
79+
'javascript-deriveOrganizationHandleFromBaseUrl-CustomDomainError-002',
80+
'javascript',
81+
'The provided base URL does not follow the expected URL pattern (/t/{orgHandle}). Please provide the organizationHandle explicitly in the configuration.',
82+
).toString(),
9283
);
84+
85+
return '';
9386
}
9487

9588
const organizationHandle = pathSegments[1];
9689

9790
if (!organizationHandle || organizationHandle.trim().length === 0) {
98-
throw new AsgardeoRuntimeError(
99-
'Organization handle is required since a custom domain is configured.',
100-
'javascript-deriveOrganizationHandleFromBaseUrl-CustomDomainError-003',
101-
'javascript',
102-
'The organization handle could not be extracted from the base URL. Please provide the organizationHandle explicitly in the configuration.',
91+
console.warn(
92+
new AsgardeoRuntimeError(
93+
'Organization handle is required since a custom domain is configured.',
94+
'javascript-deriveOrganizationHandleFromBaseUrl-CustomDomainError-003',
95+
'javascript',
96+
'The organization handle could not be extracted from the base URL. Please provide the organizationHandle explicitly in the configuration.',
97+
).toString(),
10398
);
99+
100+
return '';
104101
}
105102

106103
return organizationHandle;

0 commit comments

Comments
 (0)