Course contentsShow
← Web Development
Lesson 1677 of 2,98231. Error Handling and ResilienceFree lesson

Network Error Messages

Craft clear messages for connection failures, timeouts, and server unavailability scenarios.

Network Error Messages

You'll learn how to write clear, actionable error messages when network requests fail, helping users understand what went wrong and what they can do about it.

The Problem: Vague Network Failures

When a network request fails, the browser gives you generic errors like "Failed to fetch" or "Network error." Your users deserve better. A clear network error message should explain what happened, why it might have happened, and what the user can do.

Three Common Network Scenarios

Connection Failures

When the request can't reach the server at all (offline, DNS issues, server down):

Bad: "Error occurred"
Good: "Unable to connect. Please check your internet connection and try again."

Timeouts

When the server doesn't respond within a reasonable time:

Bad: "Request failed"
Good: "The request is taking longer than expected. The server might be busy. Please wait a moment and try again."

Server Unavailability (5xx errors)

When the server is reachable but can't process the request:

Bad: "Server error"
Good: "Our servers are experiencing issues. We've been notified and are working on a fix. Please try again in a few minutes."

Think Like a Helpful Guide

Imagine you're calling a friend and the call fails. "Call failed" isn't helpful. "Can't reach Sarah—her phone might be off or she's out of signal range" tells you why and suggests what to expect.

Your error messages should do the same: acknowledge the problem, offer a likely cause in plain language, and suggest a next step.

Key Takeaway: Network error messages should be specific about what failed, explain the likely cause in user-friendly terms, and provide clear next steps like "try again" or "check your connection."