Question

I know there is plenty questions about similar but I haven't found the most good approach so hope this will help not only me.

So the question: What is the best way to display error messages in the client? On the server side on my previous website I had messages which I sent from server to client from resource file. So when user used English in the browser it returns in English. If Danish it returns in Danish language. BUT the problem with this approach with API because mobile devices also wants to see the errors in the language which configured on (let's say) android device. In this approach I can't user resource file and I should send to the client some code of error and but this code error will be got from android device's resource file. But in this approach also is a mistake because I can't return the error with some specific parameter, like username in the error message code.

In my new project I am building the errors with Custom Exceptions but there is no way to send the error which can be parametric for example like this: "John is unavailable for selected period", where John is parameter.

Was it helpful?

Solution

I have done this using parametric strings used in string.Format for example:

string.Format("{0} is unavailable for selected period", _userName);

and move the parametric string into resource file, so you can use this string in multi language resource files as well

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top