Skip to content

Commit

Permalink
fix: catch error in getUrlParam() in DefaultUserProvider (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc authored Dec 23, 2024
1 parent a1afcfa commit 007ff68
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/experiment-browser/src/providers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,20 @@ export class DefaultUserProvider implements ExperimentUserProvider {

private getUrlParam(): Record<string, string | string[]> {
if (!this.globalScope) {
return {};
return undefined;
}

const params: Record<string, string[]> = {};
for (const [name, value] of new URL(this.globalScope?.location?.href)
.searchParams) {
params[name] = [...(params[name] ?? []), ...value.split(',')];

try {
const url = new URL(this.globalScope.location.href);
for (const [name, value] of url.searchParams) {
params[name] = [...(params[name] ?? []), ...value.split(',')];
}
} catch (error) {
return undefined;
}

return Object.entries(params).reduce<Record<string, string | string[]>>(
(acc, [name, value]) => {
acc[name] = value.length == 1 ? value[0] : value;
Expand Down

0 comments on commit 007ff68

Please sign in to comment.