1- import type { Event , EventHint , SendFeedback , SendFeedbackParams , TransportMakeRequestResponse } from '@sentry/core' ;
1+ import type {
2+ Event ,
3+ EventHint ,
4+ FeedbackErrorMessages ,
5+ SendFeedback ,
6+ SendFeedbackParams ,
7+ TransportMakeRequestResponse ,
8+ } from '@sentry/core' ;
29import { captureFeedback , getClient , getCurrentScope , getLocationHref } from '@sentry/core' ;
310import { FEEDBACK_API_SOURCE } from '../constants' ;
11+ import { createFeedbackError , resolveFeedbackErrorMessage } from '../util/createFeedbackError' ;
412
513/**
614 * Public API to send a Feedback item to Sentry
715 */
816export const sendFeedback : SendFeedback = (
917 params : SendFeedbackParams ,
10- hint : EventHint & { includeReplay ?: boolean } = { includeReplay : true } ,
18+ hint : EventHint & { includeReplay ?: boolean ; errorMessages ?: FeedbackErrorMessages } = { includeReplay : true } ,
1119) : Promise < string > => {
20+ const errorMessages = hint . errorMessages ;
21+
1222 if ( ! params . message ) {
13- throw new Error ( 'Unable to submit feedback with empty message' ) ;
23+ throw createFeedbackError ( 'ERROR_EMPTY_MESSAGE' , errorMessages ) ;
1424 }
1525
1626 // We want to wait for the feedback to be sent (or not)
1727 const client = getClient ( ) ;
1828
1929 if ( ! client ) {
20- throw new Error ( 'No client setup, cannot send feedback.' ) ;
30+ throw createFeedbackError ( 'ERROR_NO_CLIENT' , errorMessages ) ;
2131 }
2232
2333 if ( params . tags && Object . keys ( params . tags ) . length ) {
@@ -35,7 +45,10 @@ export const sendFeedback: SendFeedback = (
3545 // We want to wait for the feedback to be sent (or not)
3646 return new Promise < string > ( ( resolve , reject ) => {
3747 // After 30s, we want to clear anyhow
38- const timeout = setTimeout ( ( ) => reject ( 'Unable to determine if Feedback was correctly sent.' ) , 30_000 ) ;
48+ const timeout = setTimeout ( ( ) => {
49+ cleanup ( ) ;
50+ reject ( resolveFeedbackErrorMessage ( 'ERROR_TIMEOUT' , errorMessages ) ) ;
51+ } , 30_000 ) ;
3952
4053 const cleanup = client . on ( 'afterSendEvent' , ( event : Event , response : TransportMakeRequestResponse ) => {
4154 if ( event . event_id !== eventId ) {
@@ -51,14 +64,10 @@ export const sendFeedback: SendFeedback = (
5164 }
5265
5366 if ( response ?. statusCode === 403 ) {
54- return reject (
55- 'Unable to send feedback. This could be because this domain is not in your list of allowed domains.' ,
56- ) ;
67+ return reject ( resolveFeedbackErrorMessage ( 'ERROR_FORBIDDEN' , errorMessages ) ) ;
5768 }
5869
59- return reject (
60- 'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.' ,
61- ) ;
70+ return reject ( resolveFeedbackErrorMessage ( 'ERROR_GENERIC' , errorMessages ) ) ;
6271 } ) ;
6372 } ) ;
6473} ;
0 commit comments