Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make sure that DSN is always passed to report dialog #2770

Merged
merged 1 commit into from Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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