LLawsford
LLawsford

Reputation: 61

How to display error to the user in MERN stack

I got node/express api with mongoDB connected and react/redux on front-end.

How could I display errors (for example with database connection) to the user.

For example if error occurs on backend and I want to create big tag with error message in component?

Upvotes: 3

Views: 614

Answers (1)

Simone Anthony
Simone Anthony

Reputation: 696

This article show point you the right direction. I had to search for this as well:

https://itnext.io/javascript-error-handling-from-express-js-to-react-810deb5e5e28

to access error message, try this if you are using Axios...

try{
// something...
} catch(error) {
    console.log(error.response.data)
}

Upvotes: 4

Related Questions