Course contentsShow
← React
Lesson 1316 of 2,39633. Error BoundariesFree lesson

Contextual Error Messages by Location

Customize error displays based on where the boundary sits: page-level vs component-level vs critical path failures.

Contextual Error Messages by Location

What you'll learn: How to show different error messages and recovery options depending on where your error boundary is positioned in the component tree.

Not all errors are created equal. A crash in your navigation bar is far more critical than a broken comment widget. Your error boundaries should reflect this by showing contextual messages that match the severity and scope of the failure.

The Location Context Pattern

Error boundaries can detect where they sit in your app and adjust their messaging accordingly:

App-level boundaries caught a catastrophic failure. Show a full-page error with a "Reload App" button. This is user-facing language for "everything broke."

Route/page-level boundaries caught a page crash. Display "This page failed to load" with a link back to the homepage. The rest of your app still works, so give users an escape route.

Component-level boundaries caught a widget failure. Show an inline message like "Unable to load comments" with a retry button. The page itself is fine, just this one piece is broken.

Critical path boundaries (like checkout flows) need urgent language: "Payment processing unavailable—please contact support" rather than a generic error.

Why This Matters

The boundary's location determines:

  • User impact severity – Did one button break, or the entire app?
  • Recovery options – Retry this component vs navigate away vs reload everything
  • Message tone – Apologetic for app crashes, matter-of-fact for widgets
  • Logging priority – Page errors are high-priority, widget errors are informational

You can pass location context via props to your error boundary: <ErrorBoundary level="page" feature="Dashboard" />, then customize the fallback UI based on those props.

Key Takeaway: Error boundaries should display contextually appropriate messages and recovery actions based on their position in the component tree—app crashes need different messaging than widget failures.