Skip to content

Commit eb39c3e

Browse files
committed
change dsn logic
1 parent 6df9533 commit eb39c3e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/browser/src/sdk.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = g
135135
return;
136136
}
137137

138-
if (!options.dsn) {
139-
IS_DEBUG_BUILD && logger.error('Missing dsn option in showReportDialog call');
138+
const { client, scope } = hub.getStackTop();
139+
const dsn = options.dsn || (client && client.getDsn());
140+
if (!dsn) {
141+
IS_DEBUG_BUILD && logger.error('DSN not configured for showReportDialog call');
140142
return;
141143
}
142144

143-
const scope = hub.getScope();
144145
if (scope) {
145146
options.user = {
146147
...scope.getUser(),
@@ -154,7 +155,7 @@ export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = g
154155

155156
const script = global.document.createElement('script');
156157
script.async = true;
157-
script.src = getReportDialogEndpoint(options.dsn, options);
158+
script.src = getReportDialogEndpoint(dsn, options);
158159

159160
if (options.onLoad) {
160161
// eslint-disable-next-line @typescript-eslint/unbound-method

packages/core/src/api.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ export function getReportDialogEndpoint(
118118
}
119119

120120
if (key === 'user') {
121-
if (!dialogOptions.user) {
121+
const user = dialogOptions.user;
122+
if (!user) {
122123
continue;
123124
}
124-
if (dialogOptions.user.name) {
125-
encodedOptions += `&name=${encodeURIComponent(dialogOptions.user.name)}`;
125+
if (user.name) {
126+
encodedOptions += `&name=${encodeURIComponent(user.name)}`;
126127
}
127-
if (dialogOptions.user.email) {
128-
encodedOptions += `&email=${encodeURIComponent(dialogOptions.user.email)}`;
128+
if (user.email) {
129+
encodedOptions += `&email=${encodeURIComponent(user.email)}`;
129130
}
130131
} else {
131132
encodedOptions += `&${encodeURIComponent(key)}=${encodeURIComponent(dialogOptions[key] as string)}`;

0 commit comments

Comments
 (0)