BolEnglishLearn · Play · Win
Login

🚦 API & Integration · APIs & Integration

🚦

Error Handling

API ConceptIntermediateModule 5

Return useful, consistent errors without exposing sensitive internals.

Consumers need to know what failed and what action is possible.

💡 In practice

Return a validation code for missing postal code rather than a generic server error.

🖼️ CONCEPT PICTURE
A picture to help remember Error Handling
Return a validation code for missing postal code rather than a generic server error.

💡 A good error is like a helpful road sign: it tells you what went wrong and which way to go, without handing out the map of the whole city.

💡 Learn🛠️ Apply🎯 Check

💡 Why it matters

When an API fails, the caller needs to know whether to fix their request, retry later, or give up. Clear, consistent errors make integrations robust and debuggable. Leaking internal details, on the other hand, confuses callers and hands attackers useful clues.

🛠️ How to achieve it

1
Be consistent
Use one error shape everywhere, with a code, a message and any relevant details.
2
Say what is wrong
Tell the caller which field or rule failed so they can correct the request.
3
Hide internals
Never return stack traces or database details to the outside; log them privately instead.
4
Match the status code
Use the right code so callers can distinguish a bad request from a server fault.

⚠️ Signs of trouble

  • •Every failure returns a vague 500 with no detail.
  • •Error shapes differ from one endpoint to another.
  • •Stack traces and internal paths leak to callers.
  • •Callers cannot tell a client mistake from a server fault.
⚠️ Common mistake: Returning a generic server error for problems the caller could fix, or leaking internal details. Return a specific, consistent error that names the problem, and keep internals in private logs.

🎯 Quick check

Score: 0/3

Three questions to test the idea.

  1. 1. Why return a specific error instead of a generic 500?

    Answer: So the caller knows what failed and can react

    A specific error tells the caller whether to fix the request, retry or stop — a vague 500 leaves them guessing.

  2. 2. What should an API error NOT include?

    Answer: Internal stack traces and database details

    Leaking internals confuses callers and helps attackers; keep those in private logs and return a clean, useful error.

  3. 3. Why keep a consistent error shape across endpoints?

    Answer: So consumers can handle errors with one approach

    One consistent error shape lets consumers parse and handle failures uniformly instead of coding for each endpoint.

🔑 Key terms

Error code
A short, stable identifier for a kind of failure.
Status code
The HTTP number showing how the request went.
Stack trace
Internal error detail that should stay in private logs.
Client error
A failure caused by the caller's request, like missing data.

✅ Review checklist

📊 Your progress

0%
Mark this topic learned to track it.
Saved in this browser.
🚀 Got it?
Mark it learned and move to the next topic.
Next topic →