The Page Should Never Crash! How to Handle Errors in Web Applications the Right Way!

Fri, April 4, 2025 - 3 min read
Error notification in an app

The Page Should Always Be Alive! How to Handle Errors in Web Applications the Right Way

What makes a website good? Speed, usability, and stability. But even the best services break sometimes. The question isn’t whether errors will happen, but how you handle them.

Proper error handling isn’t just technical hygiene. It’s about:

  • Protecting the user experience (UX),
  • Building product trust,
  • Improving SEO and conversion rates,
  • Making it easier to detect and fix the problem.

💥 Why Error Handling Is Critical

Imagine a user opens a page and sees… a 500 error, or even a blank screen. No explanation. No “Back” button. No hope.

That kind of experience:

  • frustrates users,
  • casts doubt on product quality,
  • leads to user churn,
  • worsens behavioral signals, which affects search rankings.

✅ Key Principles of Error Handling

1. Always notify users when an error occurs

Silence is worse than a bad explanation. Use:

  • 🔹 Popups (toast notifications or modals),
  • 🔹 Top-page banners,
  • 🔹 Inline messages in context (e.g., “Failed to load comments”).

2. Write clear and friendly messages

Avoid scary technical jargon like:

Unhandled exception at line 238: Cannot read property ‘map’ of undefined

Much better:

❌ Oops! Failed to load your bonus information. Please refresh the page or try again later.

3. Include an error code or event ID

This helps:

  • The user — feel acknowledged,
  • Support — quickly locate and fix the issue.

Example:

⚠️ ❌ Oops! Failed to load your orders. Please refresh the page or try again later. Error ID - 647565!


🚫 Examples of Bad vs Good UX for Errors

❌ What NOT to do:

  • Message: 500 Error
  • Entire screen is broken
  • No feedback or recovery options

✅ What TO DO:

  • Message: “Something went wrong. We’re aware of it and fixing the issue. Error code: #98765”
  • Part of the interface still works
  • There’s a way to return or refresh

🧰 SUPER IMPORTANT!!!

🔧 Write custom error messages for each specific failure scenario:

  • If the promo code service is down, say:

    ⚠️ ❌ Oops! Failed to load promo code information. Please refresh the page or try again later. Error ID - 647565!

  • If the order service is down:

    ⚠️ ❌ Oops! Failed to load your order data. Please refresh the page or try again later. Error ID - 647565! Or contact our support team.

  • If the content failed to load:

    ⚠️ ❌ Oops! Failed to load page content. Please refresh the page or try again later. Error ID - 647565! You can also contact our support team. Please attach a screenshot or provide the error number.

    💡 If each request has a unique error message, you — as a developer or product owner — will be able to quickly understand what broke and fix it faster.


🧰 Technical Tips

🔧 On the Frontend:

  • Use try { ... } catch (error) { ... } for API calls
  • In React — apply Error Boundaries so that a single error doesn’t crash the whole component:
class ErrorBoundary extends React.Component {
	state = { hasError: false };
 
	static getDerivedStateFromError(error) {
		return { hasError: true };
	}
 
	render() {
		if (this.state.hasError) {
			return <h2>Something went wrong.</h2>;
		}
		return this.props.children;
	}
}
  • Use optional chaining (?.)
// Instead of&nbsp;user.address.street →
const street = user?.address?.street || 'Not specified';
 
// For methods:
const result = api.getData?.().catch(handleError);
  • Use fallback values with ?? and ||
// 0&nbsp;if&nbsp;null/undefined
const price = product?.price ?? 0;
// Empty string → 'Guest'
const name = user?.name || 'Guest';

📝 Conclusion

Good error handling means:

  • 📢 Clear, human-friendly error messages,
  • 🧩 A recoverable, usable interface,
  • 🛠️ Easier debugging and tracing,
  • 💡 Increased user trust,
  • 📈 Improved SEO.

Don’t let your site go silent when things break.