From the course: Building React and ASP.NET Core Applications
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Handling errors in React
From the course: Building React and ASP.NET Core Applications
Handling errors in React
- [Instructor] The way we have built our app so far assumes that our code is perfect and it will always work but any developer can tell you that is never the case. So, let us learn how to handle errors in React. For that, let's go to Visual Code and see the action. In here, we are going to start from the API, so let's go to the Controller. So, I'll choose Controller and in here, I'll just assume that something will go wrong with the GetTrips. Now, to handle that case in here, we need to put all the code inside the API endpoint GetTrips inside a try-catch block. So, I'll just write in here try and then we write in here catch and then Exception to catch any type of exception, and add ex. And then we want to put all the logic inside the try block. And in the catch, you're now going to return a BadRequest in this case. And in the catch block, I'll just return a BadRequest. So I'll just write in here, something went wrong,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
React key concepts3m 5s
-
(Locked)
Designing the Trips page10m 47s
-
(Locked)
Reading data from React10m 45s
-
(Locked)
Designing the Create page6m 4s
-
(Locked)
Adding new data from React9m 48s
-
(Locked)
Challenge: Updating data from React49s
-
(Locked)
Solution: Updating data from React14m 36s
-
(Locked)
Deleting data from React10m 11s
-
(Locked)
Handling errors in React6m 26s
-
-
-
-