This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
Allow custom error handling for i18n errors #550
Merged
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.
Right now, when a translation is missing (or in a few other cases), we throw an error from the i18n library and are done with it. IMO this is the proper default; React provides ways to catch this error in the tree and recover gracefully. However, Web has been bitten a few times by this where incomplete test coverage/ being a little careless with the translations + no additional error handling means that the whole page gets wiped.
This PR adds the necessary hook for us to catch the error. With this PR, if the error is not re-thrown by the
onError
handler, it will return an empty string instead. IMO this is not really better than the default (since the content will not make sense), and it means that in some cases we still have errors thrown (where we can't return any sensible "default" result), but I seem to be in the minority opinion on this.