-
Notifications
You must be signed in to change notification settings - Fork 3
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
fix error throwing in save message #152
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you, I approve of merging this pull request. I've noted a couple of further improvements that I think we will want to do, but we can defer those to a later pull request.
@@ -85,7 +85,12 @@ export default async function updateTranslation( | |||
const foundId = messageIds.find((id) => id == messageId); | |||
|
|||
if (foundId === undefined) { | |||
throw new MessageNotFound(languageName, messageId); |
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.
This was the only use of MessageNotFound
Lines 7 to 11 in ae85208
export class MessageNotFound extends Error { | |
constructor(lang: string, msgId: string) { | |
super(`Message ${msgId} for language ${lang} not found`); | |
} | |
} |
Removing the last usage is an excellent opportunity to also remove the unused source code. I believe unused source code makes the project harder to maintain.
Let's remember to remove MessageNotFound
after merging this pull request.
@@ -85,7 +85,12 @@ export default async function updateTranslation( | |||
const foundId = messageIds.find((id) => id == messageId); | |||
|
|||
if (foundId === undefined) { | |||
throw new MessageNotFound(languageName, messageId); | |||
return { | |||
errorMessage: 'Message Id not found', |
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.
The value for errorMessage
is what will be displayed to the user.
lyra/webapp/src/components/MessageForm.tsx
Lines 279 to 286 in ae85208
<Alert | |
onClose={onDismissSnackbar} | |
severity="error" | |
sx={{ width: '100%' }} | |
variant="filled" | |
> | |
{state.errorMessage} | |
</Alert> |
'Failed to update translation' is not a very helpful error message to the user. What can she do with that information? Still, it is much better than the save button just animating forever.
Let's remember to improve this further after merging this pull request.
Configure ESLint to warn instead of fail the build on unused variables. In #152 this rule blocks merging even though the added value from the pull request by far outweighs the introduced inconvenience. The reviewer can decide for herself instead wether unused variables needs to be fixed before or after merging.
Description
fix error thrown on saving translation
prior to the fix, on click on save, it only kept 'thinking' forever
Changes
replace 'throw' with a return error message object
Notes to reviewer
thank you for all your help
tested the issue by changing the if statement to if (true) in order to see the error no matter what
Related issues
Resolves #146