Should messages that will be shown to the client be shown from the client-side or from the server-side? Any (dis)advantages that you can think of between the two approaches?
If the we maintain sensitive information and different sets of data is maintained by users with different sets of roles, would exposing all the message templates in the client-side be security a issue?
Client side:
httpService.post('/someEndpoint', requestBody)
.subscribe(json => {
if(json.errorCode) {
// the error service will retrieve the error template
// for such errorCode and replace placeholder with
// values from the requestBody
errorService.alert(json.errorCode, requestBody);
}
});
Server side:
if(hasErrors) {
// sets the response error code and error message
apiResponse.error(errorCode, requestBody);
}
Client callback:
httpService.post('/someEndpoint', requestBody)
.subscribe(json => {
if(json.errorCode) {
errorService.alert(json.message);
}
});
What do you think?
Gergely Polonkai
You have to believe in things that are not true. How else would they become?
Depends, as usual.
If your backend is language agnostic, and your front-end is multilingual, the backend should only send an error code, which can be transformed into a user-readable error message.
If the backend otherwise sends translated messages to the front-end, it doesn’t really matter, but I sense some coupling issues here.
If the whole backend+frontend combo is in one language, it also doesn’t matter, but your product is less marketable.
Always aim for easy i18n and l10n.