MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / sendFeedback

Function sendFeedback

packages/feedback/src/core/sendFeedback.ts:16–73  ·  view source on GitHub ↗
(
  params: SendFeedbackParams,
  hint: EventHint & { includeReplay?: boolean; errorMessages?: FeedbackErrorMessages } = { includeReplay: true },
)

Source from the content-addressed store, hash-verified

14 * Public API to send a Feedback item to Sentry
15 */
16export const sendFeedback: SendFeedback = (
17 params: SendFeedbackParams,
18 hint: EventHint & { includeReplay?: boolean; errorMessages?: FeedbackErrorMessages } = { includeReplay: true },
19): Promise<string> => {
20 const errorMessages = hint.errorMessages;
21
22 if (!params.message) {
23 throw createFeedbackError('ERROR_EMPTY_MESSAGE', errorMessages);
24 }
25
26 // We want to wait for the feedback to be sent (or not)
27 const client = getClient();
28
29 if (!client) {
30 throw createFeedbackError('ERROR_NO_CLIENT', errorMessages);
31 }
32
33 if (params.tags && Object.keys(params.tags).length) {
34 getCurrentScope().setTags(params.tags);
35 }
36 const eventId = captureFeedback(
37 {
38 source: FEEDBACK_API_SOURCE,
39 url: getLocationHref(),
40 ...params,
41 },
42 hint,
43 );
44
45 // We want to wait for the feedback to be sent (or not)
46 return new Promise<string>((resolve, reject) => {
47 // After 30s, we want to clear anyhow
48 const timeout = setTimeout(() => {
49 cleanup();
50 reject(resolveFeedbackErrorMessage('ERROR_TIMEOUT', errorMessages));
51 }, 30_000);
52
53 const cleanup = client.on('afterSendEvent', (event: Event, response: TransportMakeRequestResponse) => {
54 if (event.event_id !== eventId) {
55 return;
56 }
57
58 clearTimeout(timeout);
59 cleanup();
60
61 // Require valid status codes, otherwise can assume feedback was not sent successfully
62 if (response?.statusCode && response.statusCode >= 200 && response.statusCode < 300) {
63 return resolve(eventId);
64 }
65
66 if (response?.statusCode === 403) {
67 return reject(resolveFeedbackErrorMessage('ERROR_FORBIDDEN', errorMessages));
68 }
69
70 return reject(resolveFeedbackErrorMessage('ERROR_GENERIC', errorMessages));
71 });
72 });
73};

Callers 2

wrappedSendFeedbackFunction · 0.90

Calls 12

createFeedbackErrorFunction · 0.90
getClientFunction · 0.90
getCurrentScopeFunction · 0.90
captureFeedbackFunction · 0.90
getLocationHrefFunction · 0.90
setTimeoutFunction · 0.85
cleanupFunction · 0.85
setTagsMethod · 0.80
keysMethod · 0.65
onMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected