Skip to content

Commit 991418d

Browse files
authored
fix: Expose and repair report dialog (#1522)
* fix: Expose and repair report dialog * fix: Add default empty object for report dialog
1 parent 36ec575 commit 991418d

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

packages/browser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export { getHubFromCarrier, getCurrentHub, Hub, Scope } from '@sentry/hub';
1919

2020
export { BrowserBackend, BrowserOptions } from './backend';
2121
export { BrowserClient } from './client';
22-
export { defaultIntegrations, init } from './sdk';
22+
export { defaultIntegrations, init, lastEventId, showReportDialog } from './sdk';
2323
export { SDK_NAME, SDK_VERSION } from './version';
2424

2525
import * as Integrations from './integrations';

packages/browser/src/sdk.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { initAndBind } from '@sentry/core';
2+
import { getCurrentHub } from '@sentry/hub';
3+
import { DsnLike } from '@sentry/types';
24
import { BrowserOptions } from './backend';
35
import { BrowserClient } from './client';
46
import {
@@ -69,3 +71,46 @@ export const defaultIntegrations = [
6971
export function init(options: BrowserOptions): void {
7072
initAndBind(BrowserClient, options, defaultIntegrations);
7173
}
74+
75+
/**
76+
* Present the user with a report dialog.
77+
*
78+
* @param options Everything is optional, we try to fetch all info need from the global scope.
79+
*/
80+
export function showReportDialog(
81+
options: {
82+
[key: string]: any;
83+
eventId?: string;
84+
dsn?: DsnLike;
85+
user?: {
86+
email?: string;
87+
name?: string;
88+
};
89+
lang?: string;
90+
title?: string;
91+
subtitle?: string;
92+
subtitle2?: string;
93+
labelName?: string;
94+
labelEmail?: string;
95+
labelComments?: string;
96+
labelClose?: string;
97+
labelSubmit?: string;
98+
errorGeneric?: string;
99+
errorFormEntry?: string;
100+
successMessage?: string;
101+
} = {},
102+
): void {
103+
if (!options.eventId) {
104+
options.eventId = getCurrentHub().lastEventId();
105+
}
106+
(getCurrentHub().getClient() as BrowserClient).showReportDialog(options);
107+
}
108+
109+
/**
110+
* This is the getter for lastEventId.
111+
*
112+
* @returns The last event id of a captured event.
113+
*/
114+
export function lastEventId(): string | undefined {
115+
return getCurrentHub().lastEventId();
116+
}

packages/core/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class API {
7373
const endpoint = `${this.getBaseUrl()}${dsn.path ? `/${dsn.path}` : ''}/api/embed/error-page/`;
7474

7575
const encodedOptions = [];
76+
encodedOptions.push(`dsn=${dsn.toString()}`);
7677
for (const key in dialogOptions) {
7778
if (key === 'user') {
7879
if (!dialogOptions.user) {

packages/core/test/lib/api.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ describe('API', () => {
2121
});
2222
test('getReportDialogEndpoint', () => {
2323
expect(new API(dsnPublic).getReportDialogEndpoint({})).toEqual(
24-
'https://sentry.io:1234/subpath/api/embed/error-page/',
24+
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123',
2525
);
2626
expect(
2727
new API(dsnPublic).getReportDialogEndpoint({
2828
eventId: 'abc',
2929
testy: '2',
3030
}),
31-
).toEqual('https://sentry.io:1234/subpath/api/embed/error-page/?eventId=abc&testy=2');
31+
).toEqual(
32+
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc&testy=2',
33+
);
3234

3335
expect(
3436
new API(dsnPublic).getReportDialogEndpoint({
@@ -38,14 +40,18 @@ describe('API', () => {
3840
name: 'yo',
3941
},
4042
}),
41-
).toEqual('https://sentry.io:1234/subpath/api/embed/error-page/?eventId=abc&name=yo&email=email');
43+
).toEqual(
44+
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc&name=yo&email=email',
45+
);
4246

4347
expect(
4448
new API(dsnPublic).getReportDialogEndpoint({
4549
eventId: 'abc',
4650
user: undefined,
4751
}),
48-
).toEqual('https://sentry.io:1234/subpath/api/embed/error-page/?eventId=abc');
52+
).toEqual(
53+
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc',
54+
);
4955
});
5056
test('getDsn', () => {
5157
expect(new API(dsnPublic).getDsn()).toEqual(new Dsn(dsnPublic));

0 commit comments

Comments
 (0)