The Page Should Never Crash! 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:
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:
Silence is worse than a bad explanation. Use:
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.
This helps:
Example:
⚠️ ❌ Oops! Failed to load your orders. Please refresh the page or try again later. Error ID - 647565!
500 Error
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.
try { ... } catch (error) { ... }
for API callsclass 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;
}
}
?.
)// Instead of user.address.street →
const street = user?.address?.street || 'Not specified';
// For methods:
const result = api.getData?.().catch(handleError);
??
and ||
// 0 if null/undefined
const price = product?.price ?? 0;
// Empty string → 'Guest'
const name = user?.name || 'Guest';
Good error handling means:
Don’t let your site go silent when things break.