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

Server Error Messages (5xx)

Present internal server errors to users without exposing technical stack traces or implementation details.

Server Error Messages (5xx)

You'll learn how to present 5xx server errors to users in a friendly, safe way without exposing sensitive backend details.

What Are 5xx Errors?

Server error responses (500-599 status codes) indicate something went wrong on the backend—database failures, uncaught exceptions, overloaded servers, or misconfigured services. Unlike 4xx errors (which signal client mistakes), these are server-side problems.

The Security Risk

When a server crashes, it might return a detailed error message or stack trace showing:

  • File paths (/var/www/app/controllers/UserController.php)
  • Database connection strings
  • Framework versions and library names
  • Code snippets with logic exposed

This is like leaving your house blueprints on the front porch—it tells attackers exactly how your system is built and where vulnerabilities might exist.

Safe Error Messages for Users

Your user-facing message should be:

  1. Generic and apologetic: "Something went wrong on our end. Please try again later."
  2. Actionable when possible: "We're aware of the issue and working to fix it."
  3. Free of technical jargon: No mention of "NullPointerException" or "Connection timeout to MySQL cluster."

Implementation Pattern

When you detect a 5xx response:

if (response.status >= 500) {
  showErrorMessage(
    "We're experiencing technical difficulties. " +
    "Please try again in a few minutes."
  );
}

Behind the scenes, log the full error details to your monitoring system—but never show them to the user.

Why This Matters

You're protecting two things: your system's architecture (security) and your user's peace of mind (experience). Users don't need to know your database crashed—they just need reassurance that you're handling it.

Key Takeaway: Display generic, friendly messages for 5xx errors to users while logging full technical details privately for debugging.