Customize ajax error message when DEBUG = False
duduklein opened this issue · 1 comments
Hi,
When an error occurs in production, we get, by default, an alert with the message "An error occurred while processing an AJAX request."
I know we can override the onError javascript function to display a custom message, but it would be helpful to be able to customize the default message. The current message is very "developer" oriented message, but not very user friendly (many users don't even know what an AJAX request is).
Besides, my sites are in French and Italian and I would like them to have by default a message in their own language.
I see 2 ways to achieve the above:
- add a ugettext_lazy to the shortcuts.py file where the message is hard-coded. This way, we can always translate the sentence above to something completely different (more user friendly) even in English.
- add a variable in the settings and use it instead of the hard-coded message. The hard-coded message would be used in the case the variable is not set in the settings file. The user would put the ugettext/ugettext_lazy is his settings directly or not according to his own needs. In this cause, we could create a dictionnary DJANGO_AJAX and add all the settings related to this app into it (like django-rest-framework does). This avoids having multiple variables across the settings.
I prefer the option 2, but am obviously open to discussion.
I'm willing to implement it and make a pull request if you agree.
What do you think?
Thanks
@duduklein Great! the option 2 is better, creates a pull request. I'm sorry not to continue improving this utility. Thanks.