Skip to content

Commit

Permalink
fix: Make sure that DSN is always passed to report dialog (#2770)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Jul 23, 2020
1 parent 7956bd8 commit b24387b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
19 changes: 5 additions & 14 deletions packages/browser/src/client.ts
Expand Up @@ -68,22 +68,13 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
}

if (!this._isEnabled()) {
logger.error('Trying to call showReportDialog with Sentry Client is disabled');
logger.error('Trying to call showReportDialog with Sentry Client disabled');
return;
}

const dsn = options.dsn || this.getDsn();

if (!options.eventId) {
logger.error('Missing `eventId` option in showReportDialog call');
return;
}

if (!dsn) {
logger.error('Missing `Dsn` option in showReportDialog call');
return;
}

injectReportDialog(options);
injectReportDialog({
...options,
dsn: options.dsn || this.getDsn(),
});
}
}
14 changes: 11 additions & 3 deletions packages/browser/src/helpers.ts
@@ -1,6 +1,6 @@
import { API, captureException, withScope } from '@sentry/core';
import { DsnLike, Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
import { addExceptionMechanism, addExceptionTypeValue } from '@sentry/utils';
import { addExceptionMechanism, addExceptionTypeValue, logger } from '@sentry/utils';

let ignoreOnError: number = 0;

Expand Down Expand Up @@ -191,10 +191,18 @@ export interface ReportDialogOptions {
* @hidden
*/
export function injectReportDialog(options: ReportDialogOptions = {}): void {
if (!options.eventId) {
logger.error(`Missing eventId option in showReportDialog call`);
return;
}
if (!options.dsn) {
logger.error(`Missing dsn option in showReportDialog call`);
return;
}

const script = document.createElement('script');
script.async = true;
// tslint:disable-next-line: no-non-null-assertion
script.src = new API(options.dsn!).getReportDialogEndpoint(options);
script.src = new API(options.dsn).getReportDialogEndpoint(options);

if (options.onLoad) {
script.onload = options.onLoad;
Expand Down

0 comments on commit b24387b

Please sign in to comment.