Skip to content

Commit fdc6ca4

Browse files
logaretmclaude
andcommitted
feat(feedback)!: always reject sendFeedback with an Error
Previously, sendFeedback's async rejection paths (timeout, 403, generic transport error) rejected with plain strings, while the sync-throw paths used Error instances. Unify on Error for all paths so consumers can rely on a consistent rejection shape. BREAKING CHANGE: sendFeedback now always rejects with an Error whose .message is the error code (ERROR_TIMEOUT, ERROR_FORBIDDEN, or ERROR_GENERIC). Previously these paths rejected with the raw string. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent dadaa16 commit fdc6ca4

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

packages/feedback/src/core/sendFeedback.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
} from '@sentry/core';
99
import { captureFeedback, getClient, getCurrentScope, getLocationHref } from '@sentry/core';
1010
import { FEEDBACK_API_SOURCE } from '../constants';
11-
import { createFeedbackError, resolveFeedbackErrorMessage } from '../util/createFeedbackError';
11+
import { createFeedbackError } from '../util/createFeedbackError';
1212

1313
/**
1414
* Public API to send a Feedback item to Sentry
@@ -47,7 +47,7 @@ export const sendFeedback: SendFeedback = (
4747
// After 30s, we want to clear anyhow
4848
const timeout = setTimeout(() => {
4949
cleanup();
50-
reject(resolveFeedbackErrorMessage('ERROR_TIMEOUT', errorMessages));
50+
reject(createFeedbackError('ERROR_TIMEOUT', errorMessages));
5151
}, 30_000);
5252

5353
const cleanup = client.on('afterSendEvent', (event: Event, response: TransportMakeRequestResponse) => {
@@ -64,10 +64,10 @@ export const sendFeedback: SendFeedback = (
6464
}
6565

6666
if (response?.statusCode === 403) {
67-
return reject(resolveFeedbackErrorMessage('ERROR_FORBIDDEN', errorMessages));
67+
return reject(createFeedbackError('ERROR_FORBIDDEN', errorMessages));
6868
}
6969

70-
return reject(resolveFeedbackErrorMessage('ERROR_GENERIC', errorMessages));
70+
return reject(createFeedbackError('ERROR_GENERIC', errorMessages));
7171
});
7272
});
7373
};

packages/feedback/src/modal/components/Form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export function Form({
131131
onSubmitSuccess(data, eventId);
132132
} catch (error) {
133133
DEBUG_BUILD && debug.error(error);
134-
const err = error instanceof Error ? error : new Error(String(error));
134+
const err = error as Error;
135135
setError(err.message);
136136
onSubmitError(err);
137137
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ describe('sendFeedback', () => {
290290

291291
await expect(
292292
sendFeedback({ message: 'mi' }, { errorMessages: { ERROR_FORBIDDEN: 'custom forbidden text' } }),
293-
).rejects.toMatch('custom forbidden text');
293+
).rejects.toThrow('custom forbidden text');
294294
});
295295

296296
it('falls back to default messages for codes not in errorMessages', async () => {
@@ -319,7 +319,7 @@ describe('sendFeedback', () => {
319319
email: 're@example.org',
320320
message: 'mi',
321321
}),
322-
).rejects.toMatch(
322+
).rejects.toThrow(
323323
'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.',
324324
);
325325
});
@@ -336,7 +336,7 @@ describe('sendFeedback', () => {
336336
email: 're@example.org',
337337
message: 'mi',
338338
}),
339-
).rejects.toMatch(
339+
).rejects.toThrow(
340340
'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.',
341341
);
342342
});
@@ -353,7 +353,7 @@ describe('sendFeedback', () => {
353353
email: 're@example.org',
354354
message: 'mi',
355355
}),
356-
).rejects.toMatch(
356+
).rejects.toThrow(
357357
'Unable to send feedback. This could be because this domain is not in your list of allowed domains.',
358358
);
359359
});
@@ -389,7 +389,7 @@ describe('sendFeedback', () => {
389389

390390
vi.advanceTimersByTime(30_000);
391391

392-
await expect(promise).rejects.toMatch('Unable to determine if Feedback was correctly sent.');
392+
await expect(promise).rejects.toThrow('Unable to determine if Feedback was correctly sent.');
393393

394394
vi.useRealTimers();
395395
});

0 commit comments

Comments
 (0)