fkn fkn - 1 year ago 78
AngularJS Question

Internationalization of api error messages on front end or back end?

My team is currently working on a web project where the front end uses json api provided by the back end. The technology that we use is Spring Boot and AngularJS. The api has the standard error format that looks like this:

{
"errorCode": "1111",
"message": "Error occurred: some error message",
"developerMessage": "message for developer"
}


The error response can also contain optional list of field validation errors.
The question is where should we do the translation of user error messages? Should the back end return already translated message based on request's locale or should the front end use the errorCode and it's i18n mechanism. We have i18n mechanisms both on back end (Spring i18n support) and front end (angular-translate).

What is the best practice? What are the pros and cons of each approach? Any advice is appreciated.

Answer Source

If I had to do this, I would have done it on the back end, primarily because since the backend has the locale, and is also generating the errors, it does make sense to expect localized errors from it. It would also de-couple the systems, such that, if there is any new feature/change done on the back end, and a new error is added, you do not need to release the front end piece just for the error.

Also, once this scales up, and you have multiple backend systems, the above approach just works well, since all the error generators are responsible for taking care of their respective localizations.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download