Skip to content

Commit 41e65e0

Browse files
committed
fix: Make sure that DSN is always passed to report dialog
1 parent aa60eea commit 41e65e0

File tree

6 files changed

+29
-38
lines changed

6 files changed

+29
-38
lines changed

packages/browser/src/client.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,13 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
6868
}
6969

7070
if (!this._isEnabled()) {
71-
logger.error('Trying to call showReportDialog with Sentry Client is disabled');
71+
logger.error('Trying to call showReportDialog with Sentry Client disabled');
7272
return;
7373
}
7474

75-
const dsn = options.dsn || this.getDsn();
76-
77-
if (!options.eventId) {
78-
logger.error('Missing `eventId` option in showReportDialog call');
79-
return;
80-
}
81-
82-
if (!dsn) {
83-
logger.error('Missing `Dsn` option in showReportDialog call');
84-
return;
85-
}
86-
87-
injectReportDialog(options);
75+
injectReportDialog({
76+
...options,
77+
dsn: options.dsn || this.getDsn(),
78+
});
8879
}
8980
}

packages/browser/src/helpers.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { API, captureException, withScope } from '@sentry/core';
22
import { DsnLike, Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
3-
import { addExceptionMechanism, addExceptionTypeValue } from '@sentry/utils';
3+
import { addExceptionMechanism, addExceptionTypeValue, logger } from '@sentry/utils';
44

55
let ignoreOnError: number = 0;
66

@@ -186,15 +186,31 @@ export interface ReportDialogOptions {
186186
onLoad?(): void;
187187
}
188188

189+
/**
190+
* @hidden
191+
*/
192+
function missingReportDialogPropertyLog(prop: string): void {
193+
logger.error(`Missing '${prop}' option in showReportDialog call`);
194+
}
195+
189196
/**
190197
* Injects the Report Dialog script
191198
* @hidden
192199
*/
193200
export function injectReportDialog(options: ReportDialogOptions = {}): void {
201+
if (!options.eventId) {
202+
missingReportDialogPropertyLog('eventId');
203+
return;
204+
}
205+
if (!options.dsn) {
206+
missingReportDialogPropertyLog('dsn');
207+
return;
208+
}
209+
194210
const script = document.createElement('script');
195211
script.async = true;
196212
// tslint:disable-next-line: no-non-null-assertion
197-
script.src = new API(options.dsn!).getReportDialogEndpoint(options);
213+
script.src = new API(options.dsn).getReportDialogEndpoint(options);
198214

199215
if (options.onLoad) {
200216
script.onload = options.onLoad;

packages/integrations/src/reportingobserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class ReportingObserver implements Integration {
8989

9090
this._getCurrentHub = getCurrentHub;
9191

92-
const observer = new (getGlobalObject<any>().ReportingObserver)(this.handler.bind(this), {
92+
const observer = new (getGlobalObject<any>()).ReportingObserver(this.handler.bind(this), {
9393
buffered: true,
9494
types: this._options.types,
9595
});

packages/utils/src/path.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ export function resolve(...args: string[]): string {
6060
// handle relative paths to be safe (might happen when process.cwd() fails)
6161

6262
// Normalize the path
63-
resolvedPath = normalizeArray(
64-
resolvedPath.split('/').filter(p => !!p),
65-
!resolvedAbsolute,
66-
).join('/');
63+
resolvedPath = normalizeArray(resolvedPath.split('/').filter(p => !!p), !resolvedAbsolute).join('/');
6764

6865
return (resolvedAbsolute ? '/' : '') + resolvedPath || '.';
6966
}
@@ -128,10 +125,7 @@ export function normalizePath(path: string): string {
128125
const trailingSlash = path.substr(-1) === '/';
129126

130127
// Normalize the path
131-
let normalizedPath = normalizeArray(
132-
path.split('/').filter(p => !!p),
133-
!isPathAbsolute,
134-
).join('/');
128+
let normalizedPath = normalizeArray(path.split('/').filter(p => !!p), !isPathAbsolute).join('/');
135129

136130
if (!normalizedPath && !isPathAbsolute) {
137131
normalizedPath = '.';

packages/utils/test/object.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,7 @@ describe('normalize()', () => {
204204
obj.children[1].self = obj.children[1];
205205
expect(normalize(obj)).toEqual({
206206
name: 'Alice',
207-
children: [
208-
{ name: 'Bob', self: '[Circular ~]' },
209-
{ name: 'Eve', self: '[Circular ~]' },
210-
],
207+
children: [{ name: 'Bob', self: '[Circular ~]' }, { name: 'Eve', self: '[Circular ~]' }],
211208
});
212209
});
213210

@@ -222,10 +219,7 @@ describe('normalize()', () => {
222219
const obj: object[] = [];
223220
obj.push({ name: 'Alice', self: obj });
224221
obj.push({ name: 'Bob', self: obj });
225-
expect(normalize(obj)).toEqual([
226-
{ name: 'Alice', self: '[Circular ~]' },
227-
{ name: 'Bob', self: '[Circular ~]' },
228-
]);
222+
expect(normalize(obj)).toEqual([{ name: 'Alice', self: '[Circular ~]' }, { name: 'Bob', self: '[Circular ~]' }]);
229223
});
230224

231225
test('repeated objects in objects', () => {

packages/utils/test/promisebuffer.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ describe('PromiseBuffer', () => {
1919
const q = new PromiseBuffer<void>(1);
2020
const p = new SyncPromise<void>(resolve => setTimeout(resolve, 1));
2121
expect(q.add(p)).toEqual(p);
22-
expect(
23-
q.add(
24-
new SyncPromise<void>(resolve => setTimeout(resolve, 1)),
25-
),
26-
).rejects.toThrowError();
22+
expect(q.add(new SyncPromise<void>(resolve => setTimeout(resolve, 1)))).rejects.toThrowError();
2723
expect(q.length()).toBe(1);
2824
});
2925
});

0 commit comments

Comments
 (0)