Skip to content

Commit c6d759f

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 0c3d1e1 commit c6d759f

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('handles 400 transport error', async () => {
@@ -305,7 +305,7 @@ describe('sendFeedback', () => {
305305
email: 're@example.org',
306306
message: 'mi',
307307
}),
308-
).rejects.toMatch(
308+
).rejects.toThrow(
309309
'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.',
310310
);
311311
});
@@ -322,7 +322,7 @@ describe('sendFeedback', () => {
322322
email: 're@example.org',
323323
message: 'mi',
324324
}),
325-
).rejects.toMatch(
325+
).rejects.toThrow(
326326
'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.',
327327
);
328328
});
@@ -339,7 +339,7 @@ describe('sendFeedback', () => {
339339
email: 're@example.org',
340340
message: 'mi',
341341
}),
342-
).rejects.toMatch(
342+
).rejects.toThrow(
343343
'Unable to send feedback. This could be because this domain is not in your list of allowed domains.',
344344
);
345345
});
@@ -375,7 +375,7 @@ describe('sendFeedback', () => {
375375

376376
vi.advanceTimersByTime(30_000);
377377

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

380380
vi.useRealTimers();
381381
});

0 commit comments

Comments
 (0)