Intro to Error Handling
00:00 Sometimes things happen that you don't really want to have happen. So, sometimes we have errors and it's not always our fault, but sometimes it is. Sometimes the user submitted some bad data or the form was configured incorrectly or the service that we're depending on is down and, you know, it happens.
00:19 And there are various status codes to communicate the status of an HTTP request as part of the response. And so there are these different levels. We have 100 levels. You basically never use those. You have 200 levels. That is all successful. Redirection levels is 300.
00:37 So, we want you to go somewhere else or this resource is somewhere else. And then you have 400 level. That's client error responses. And then 500 level is server error responses. So, client error responses, maybe there's a little overload on the term, but it really means the client that made this request is the one in error.
00:57 500 level is client, you didn't do anything wrong. I did something wrong. So, that's what's going on there. And there are a bunch of different kinds of options there. So, you've got bad requests and unauthorized and payment required. I've never ever used that one myself. But then forbidden and 404 not found.
01:15 That's like a major meme material. 405 we've actually already seen, method not allowed. And yeah, a bunch of others. My favorite maybe is 418, everybody's favorite, of course. But then we also have 500 level responses. Most of the time you just see 500.
01:32 Sometimes you'll see 502 or 503. But yeah, this is just like, we don't really know what happened. We weren't planning on this. So, you've got your expected errors, which are your client errors, and then your unexpected errors, which is like, I don't know, something messed up. We're not in a good place. So, we need to handle those, right?
01:50 So, when this is all done, you should have the ability to handle 404s properly with status codes. We already are throwing responses. As we learned about earlier, when we're loading data, we're using that invariant response utility. And so, we're throwing these responses.
02:08 So, we are getting proper status codes, but we want to have better error messages, error pages. And then here we also get that for when the user does not exist. And then even if a route does not exist, we get that as well. So, you're going to be building out all of this stuff.
02:27 And it's useful not just for when a route doesn't exist or, you know, 404s, but of course, you can use this for all types of errors. And the way that you do this is with RemixRunReact. It has this useRouteError hook. You export this error boundary.
02:42 And then from there, you're able to determine what the error was and display something, hopefully, relatively useful. So, I think you're going to have a great time with this one. So, good luck and may the force be with you.