Error Information Display Patterns
What you'll learn: How to decide what error details to show users versus what to log privately, keeping production apps secure and user-friendly.
When an error boundary catches an error, you face a critical decision: what information should the user see? The answer depends entirely on your environment and audience.
The Two-Audience Problem
Think of error information like medical test results. In development, you're the doctor who needs every detail—stack traces, component trees, prop values. In production, your users are patients who need reassurance and next steps, not technical jargon that confuses or frightens them.
Development: Show Everything
During development, expose the full error object:
class ErrorBoundary extends React.Component {
render() {
if (this.state.hasError) {
// Dev mode: show technical details
if (process.env.NODE_ENV === 'development') {
return (
<div>
<h1>Error occurred</h1>
<pre>{this.state.error.message}</pre>
<pre>{this.state.error.stack}</pre>
</div>
);
}
// Production: friendly message only
return (
<div>
<h1>Something went wrong</h1>
<p>We're working on fixing this issue.</p>
</div>
);
}
return this.props.children;
}
}
Production: Hide the Details
In production, users don't benefit from stack traces—they just create confusion and potentially expose security vulnerabilities. Show only:
- A friendly, non-technical message
- Action steps (refresh, contact support)
- Maybe a generic error code for support reference
Always log the full error details to your monitoring service in componentDidCatch, but keep them away from the UI.
Key Takeaway: Show full technical error details during development for debugging, but display only user-friendly messages in production while logging complete details server-side.