6

I have a general design based question regarding displaying error message from then backend to the end user in the front end. Not sure where to look for this. So the error response would be something like this

Error Status: 400 (Bad Request)
{
    value: "+++",
    errorMessage: value "+++" fails to match alpha numeric pattern

}

Now in the front end I don't want to show message directly from the backend. Since it could be of technical nature (I would log that error message from the backend). I want to display a better user friendly message something like.

"Invalid entry '+++' Numbers and texts are only allowed."

My question is how to go about this. One method I could think of is to return errorType in the response. I will then check the error type in the front end, and then display message from the front end accordingly. So my response from the backend would be something like this,

Error Status: 400 (Bad Request)
{
    value: "+++",
    errorMessage: value "++++" fails to match alpha numeric pattern
    errorType: INVALID_PATTERN
}

In the front end I would have some ENUM like

ERROR_TYPES: [
{
    INVALID_PATTERN: "Invalid entry <variable> Numbers and texts are only allowed."
}]

Is this a good approach? What is a best practice for something like this?

If you could provide some references that I could dig deeper into, would be much appreciated.

P.S. I am using the MEAN stack Thanks

Samip Suwal
  • 1,253
  • 11
  • 17
  • 1
    pro tip: open chrome dev tools in this page (F12) and try to up vote your question. Now look at the network tab. Profit. – Omri Luzon Jun 01 '17 at 19:59
  • @OmriLuzon SO seems to display error message returned in the response. Which is not what I want to do over here. – Samip Suwal Jun 01 '17 at 20:06
  • You can still use response with status codes of error, In your MEAN app it would be handled in the rejection function of a promise or observable. – Omri Luzon Jun 01 '17 at 20:39

0 Answers0