-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(feedback): allow error messages to be customized #20474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
logaretm
wants to merge
6
commits into
develop
Choose a base branch
from
awad/js-126-allow-error-messages-to-be-customized
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+173
−20
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4482787
feat(feedback): allow error messages to be customized
logaretm d7b27f6
address PR review feedback
logaretm 688409e
refactor: inject error texts via sendFeedback hint, preserve default …
logaretm 32e030f
bump size limits for feedback error-message overrides
logaretm 4333b92
test: add default-fallback test for partial errorMessages override
logaretm 029c535
fix: restore original ERROR_EMPTY_MESSAGE_TEXT wording
logaretm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { FeedbackErrorCode, FeedbackErrorMessages } from '@sentry/core'; | ||
| import { | ||
| ERROR_EMPTY_MESSAGE_TEXT, | ||
| ERROR_FORBIDDEN_TEXT, | ||
| ERROR_GENERIC_TEXT, | ||
| ERROR_NO_CLIENT_TEXT, | ||
| ERROR_TIMEOUT_TEXT, | ||
| } from '../constants'; | ||
|
|
||
| const DEFAULT_MESSAGES: Record<FeedbackErrorCode, string> = { | ||
| ERROR_EMPTY_MESSAGE: ERROR_EMPTY_MESSAGE_TEXT, | ||
| ERROR_NO_CLIENT: ERROR_NO_CLIENT_TEXT, | ||
| ERROR_TIMEOUT: ERROR_TIMEOUT_TEXT, | ||
| ERROR_FORBIDDEN: ERROR_FORBIDDEN_TEXT, | ||
| ERROR_GENERIC: ERROR_GENERIC_TEXT, | ||
| }; | ||
|
|
||
| export function resolveFeedbackErrorMessage(code: FeedbackErrorCode, messages?: FeedbackErrorMessages): string { | ||
| return messages?.[code] ?? DEFAULT_MESSAGES[code]; | ||
| } | ||
|
|
||
| export function createFeedbackError(code: FeedbackErrorCode, messages?: FeedbackErrorMessages): Error { | ||
| return new Error(resolveFeedbackErrorMessage(code, messages)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,6 +267,46 @@ describe('sendFeedback', () => { | |
| ]); | ||
| }); | ||
|
|
||
| it('throws when message is empty', () => { | ||
| mockSdk(); | ||
| expect(() => sendFeedback({ message: '' })).toThrow('Unable to submit feedback with empty message'); | ||
| }); | ||
|
|
||
| it('throws when no client is set up', async () => { | ||
| // Isolate in its own scope so the client set up by other tests doesn't bleed in. | ||
| // `getClient` reads from the current scope; resetting it here leaves no client. | ||
| const { getGlobalScope } = await import('@sentry/core'); | ||
| getGlobalScope().setClient(undefined); | ||
| getCurrentScope().setClient(undefined); | ||
| getIsolationScope().setClient(undefined); | ||
| expect(() => sendFeedback({ message: 'mi' })).toThrow('No client setup, cannot send feedback.'); | ||
| }); | ||
|
|
||
| it('uses provided errorMessages overrides', async () => { | ||
| mockSdk(); | ||
| vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => { | ||
| return Promise.resolve({ statusCode: 403 }); | ||
| }); | ||
|
|
||
| await expect( | ||
| sendFeedback({ message: 'mi' }, { errorMessages: { ERROR_FORBIDDEN: 'custom forbidden text' } }), | ||
| ).rejects.toMatch('custom forbidden text'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: maybe it could be worth adding a case where we check that non-overriden messages keep the default? |
||
| }); | ||
|
|
||
| it('falls back to default messages for codes not in errorMessages', async () => { | ||
| mockSdk(); | ||
| vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => { | ||
| return Promise.resolve({ statusCode: 400 }); | ||
| }); | ||
|
|
||
| // Only override ERROR_FORBIDDEN — a 400 should still use the default generic message. | ||
| await expect( | ||
| sendFeedback({ message: 'mi' }, { errorMessages: { ERROR_FORBIDDEN: 'custom forbidden text' } }), | ||
| ).rejects.toMatch( | ||
| 'Unable to send feedback. This could be because of network issues, or because you are using an ad-blocker.', | ||
| ); | ||
| }); | ||
|
|
||
| it('handles 400 transport error', async () => { | ||
| mockSdk(); | ||
| vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Could this be avoided by outsourcing
wrappedSendFeedback? Would still be nice to keep as manyeslintoxlint rules as possibleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complexity is coming from the massive destructions, extracting the inner function doesn't make the rule pass 😕