-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
Revamped error handling #8
Comments
Nice work!
It is more than that. You have also production running apps that are connected to translation services that affect production live (like i18next with locize.com), or deployed occasionally with new locales files that were not created by developers. Its a production issue, not dev mode - hence should be warning and not error.
Maybe you meant to it but I guess |
True, good point. With next-intl you can theoretically fetch translations from a remote resource – I wasn't sure if that's a valid use case.
Right. I was thinking about providing a useful built-in handling here, but I guess it's justified that a user might wants to customize this. I think it might be necessary to have a separate API from I've added a bullet above. My first API draft is:
By using a function we can provide as much context as we have and the user can decide case-by-case what fallback should be used. Does that look reasonable to you? |
yep, seems legit |
@amannn Nice work! |
As mentioned by @ilanbm in #6 currently we throw for missing messages.
After some research I can think of two use cases where you want to keep the app running even if messages are missing:
In both occasions it would be good to print the error by default, but opting out might be helpful.
What we could do, is to add an optional
onError
property on the provider which will allow the user to decide if and how errors should be handled. This can for example be used to turn off warnings about missing messages in unit tests.I think errors should have the following properties:
code
: An identifier that the user can detect.message
: A human readable message. This is only provided during development to reduce bundle size in production.level
: An enum withERROR
orWARN
keys but which correspond to integers to be able to do checks likeerror.level >= NextIntlErrorCode.WARN
.Generally I can think of three categories of errors currently:
NextIntlProvider
). This is anERROR
, but we can't use a user-definedonError
in this particular example, as there's no provider.WARN
level, as we can render the message instead.WARN
level and render the ID instead, as the developer might not be able to fix it.The default
onError
handler should throw an error forERROR
and print a console error forWARN
(only in development).TODO:
onError
prop to coveruseTranslations
.<NextIntlProvider getMessageFallback={({path, error, message}) => ''} />
)useIntl
functions as well. These should typically only be triggered by missing APIs (due to missing polyfills) or if the native APIs are used in an invalid way. Maybe it's ok to simply use the native error handling here as it's the developers job to fix it and there's e.g. no translator necessary.The text was updated successfully, but these errors were encountered: