diff --git a/packages/feedback/src/core/sendFeedback.ts b/packages/feedback/src/core/sendFeedback.ts index f3ae1504f9b4..712da5c269bf 100644 --- a/packages/feedback/src/core/sendFeedback.ts +++ b/packages/feedback/src/core/sendFeedback.ts @@ -46,29 +46,18 @@ export const sendFeedback: SendFeedback = ( cleanup(); // Require valid status codes, otherwise can assume feedback was not sent successfully - if ( - response && - typeof response.statusCode === 'number' && - response.statusCode >= 200 && - response.statusCode < 300 - ) { + if (response?.statusCode && response.statusCode >= 200 && response.statusCode < 300) { return resolve(eventId); } - if (response && typeof response.statusCode === 'number' && response.statusCode === 0) { + if (response?.statusCode === 403) { return reject( - 'Unable to send Feedback. This is because of network issues, or because you are using an ad-blocker.', - ); - } - - if (response && typeof response.statusCode === 'number' && response.statusCode === 403) { - return reject( - 'Unable to send Feedback. This could be because this domain is not in your list of allowed domains.', + 'Unable to send feedback. This could be because this domain is not in your list of allowed domains.', ); } return reject( - 'Unable to send Feedback. This could be because of network issues, or because you are using an ad-blocker', + 'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.', ); }); }); diff --git a/packages/feedback/test/core/sendFeedback.test.ts b/packages/feedback/test/core/sendFeedback.test.ts index 2d728e710178..a0cbb084da59 100644 --- a/packages/feedback/test/core/sendFeedback.test.ts +++ b/packages/feedback/test/core/sendFeedback.test.ts @@ -280,7 +280,7 @@ describe('sendFeedback', () => { message: 'mi', }), ).rejects.toMatch( - 'Unable to send Feedback. This could be because of network issues, or because you are using an ad-blocker', + 'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.', ); }); @@ -297,7 +297,24 @@ describe('sendFeedback', () => { message: 'mi', }), ).rejects.toMatch( - 'Unable to send Feedback. This is because of network issues, or because you are using an ad-blocker.', + 'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.', + ); + }); + + it('handles 403 transport error', async () => { + mockSdk(); + vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => { + return Promise.resolve({ statusCode: 403 }); + }); + + await expect( + sendFeedback({ + name: 'doe', + email: 're@example.org', + message: 'mi', + }), + ).rejects.toMatch( + 'Unable to send feedback. This could be because this domain is not in your list of allowed domains.', ); });