Skip to content

User Friendly Messages

DodaTech 2 min read

title: "User-Friendly Error Messages — Writing Clear API Error Responses" description: "User-friendly API error messages explain what went wrong, why it happened, and how to fix it, using clear language appropriate for the developer audience." date: 2026-06-28 lastmod: 2026-06-28 weight: 24 tags: [apis, error-handling] }

User-friendly API error messages clearly explain the problem, its cause, and how to fix it, helping developers resolve issues without contacting support.

What You'll Learn

  • Principles of clear error messages
  • Including actionable guidance
  • Balancing detail with security

Why It Matters

Good error messages save developer time. Every unclear error message creates a potential support ticket.

Principles

Principle Bad Example Good Example
Specific "Bad request" "Email format is invalid"
Actionable "Access denied" "Add 'users:read' scope to your API key"
Contextual "Missing field" "The 'name' field is required when creating a user"
Tone "You sent a bad request" "The request couldn't be processed because..."

Code Examples

// Bad error messages
{
  "error": "Bad Request",
  "message": "Invalid input"
}

// Good error messages
{
  "error": "VALIDATION_ERROR",
  "message": "The request contains invalid fields",
  "fields": [
    {
      "name": "email",
      "value": "not-an-email",
      "reason": "Must be a valid email address (e.g., user@example.com)",
      "how_to_fix": "Provide a valid email address in the standard format"
    }
  ]
}

// Auth error with actionable guidance
{
  "error": "FORBIDDEN",
  "message": "You don't have permission to delete users",
  "required_scope": "users:delete",
  "how_to_fix": "Generate a new API key with the 'users:delete' scope at https://dashboard.example.com/api-keys"
}

Common Mistakes

1. Vague Messages

"An error occurred" tells the developer nothing useful.

2. Blaming the Developer

"The request was invalid" vs "The 'age' field must be a positive number".

3. No Next Steps

Tell developers what to do to fix the error.

4. Too Much Technical Detail

"IndexOutOfBoundsException" means nothing to most API consumers.

5. Inconsistent Language

Mix of developer-friendly and user-facing language confuses.

Practice Questions

  1. What three pieces of information should every error message include?
  2. Why should error messages include "how to fix" guidance?
  3. What is the balance between detail and security?
  4. How do error messages affect support ticket volume?
  5. What tone should API error messages use?

Answers:

  1. What went wrong, why it happened, and how to fix it.
  2. So developers can resolve the issue without contacting support.
  3. Be specific about the error but never expose internal implementation.
  4. Clear messages reduce tickets; vague messages increase them.
  5. Professional, helpful, and solution-oriented.

Challenge: Rewrite 5 poorly-written error messages from a real API into user-friendly versions that include the problem, cause, and solution.

FAQ

Should error messages include technical details?

: Include enough for a developer to understand, but never stack traces or internal paths.

How long should an error message be?

: 1-3 sentences. Provide details in structured fields.

Should I localize error messages?

: If your API has international developers, yes. At minimum use English.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro