Error Handling in Remix
Error handling is an important part of building resilient user experiences. We can distinguish two kinds of errors:
- Unexpected errors, such as network timeouts
- Expected failures (exceptions) thrown on purpose
Remix provides primitives and conventions to handle both unexpected and expected errors uniformly. This chapter covers the following topics:
- Dealing with unexpected errors
- Handling thrown responses
- Handling page-not-found (404) errors
First, we will fabricate some unexpected errors and learn how to handle them. Next, we will review the difference between returning and throwing Response
objects in loader
and action
functions. We will see how we can handle thrown responses with Remix’s ErrorBoundary
. Finally, we will add not-found error handling to BeeRich.
After reading this chapter, you will understand how to manage both unexpected and expected failures in Remix declaratively using Remix’s ErrorBoundary...