Skip to content

Commit 72a83b3

Browse files
committed
more cleanup & tests
1 parent 4de45f9 commit 72a83b3

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

packages/feedback/src/core/sendFeedback.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,18 @@ export const sendFeedback: SendFeedback = (
4646
cleanup();
4747

4848
// Require valid status codes, otherwise can assume feedback was not sent successfully
49-
if (
50-
response &&
51-
typeof response.statusCode === 'number' &&
52-
response.statusCode >= 200 &&
53-
response.statusCode < 300
54-
) {
49+
if (response?.statusCode && response.statusCode >= 200 && response.statusCode < 300) {
5550
return resolve(eventId);
5651
}
5752

58-
if (response && typeof response.statusCode === 'number' && response.statusCode === 403) {
53+
if (response?.statusCode === 403) {
5954
return reject(
60-
'Unable to send Feedback. This could be because this domain is not in your list of allowed domains.',
55+
'Unable to send feedback. This could be because this domain is not in your list of allowed domains.',
6156
);
6257
}
6358

6459
return reject(
65-
'Unable to send Feedback. This could be because of network issues, or because you are using an ad-blocker',
60+
'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.',
6661
);
6762
});
6863
});

packages/feedback/test/core/sendFeedback.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ describe('sendFeedback', () => {
280280
message: 'mi',
281281
}),
282282
).rejects.toMatch(
283-
'Unable to send Feedback. This could be because of network issues, or because you are using an ad-blocker',
283+
'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.',
284284
);
285285
});
286286

@@ -297,7 +297,24 @@ describe('sendFeedback', () => {
297297
message: 'mi',
298298
}),
299299
).rejects.toMatch(
300-
'Unable to send Feedback. This is because of network issues, or because you are using an ad-blocker.',
300+
'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.',
301+
);
302+
});
303+
304+
it('handles 403 transport error', async () => {
305+
mockSdk();
306+
vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
307+
return Promise.resolve({ statusCode: 403 });
308+
});
309+
310+
await expect(
311+
sendFeedback({
312+
name: 'doe',
313+
314+
message: 'mi',
315+
}),
316+
).rejects.toMatch(
317+
'Unable to send feedback. This could be because this domain is not in your list of allowed domains.',
301318
);
302319
});
303320

0 commit comments

Comments
 (0)