# Prompting For Error Handling That Is Not Just try/catch

> Named error classes, correlation IDs, and a rule about what never reaches the client.

- **Author:** [Kabir Singh (@kabir_singh)](https://www.promptabide.com/kabir_singh)
- **Published:** 2026-02-27
- **Updated:** 2026-08-22
- **Tags:** `backend`, `node`, `error-handling`, `reliability`
- **Views:** 6080
- **Likes:** 338

## Prompt

```
Ask for "error handling" and you get try/catch wrapped around everything with console.log in the catch. Ask for this instead:

"Add error handling to this module. Requirements:
- A small hierarchy: AppError base, then ValidationError, NotFoundError, ConflictError, ExternalServiceError
- Each carries an HTTP status and a machine-readable code
- One central Express error middleware maps them to responses
- Unknown errors become a 500 with a correlation ID; the real message goes to the logger, never to the client
- Stack traces only when NODE_ENV !== production
- External calls get a timeout and one retry with backoff; a retry exhaustion is an ExternalServiceError, not a 500"

The line that earns its place is "the real message goes to the logger, never to the client". Without it you leak table names in 500 bodies.
```

---

Canonical HTML: https://www.promptabide.com/bides/prompt-real-error-handling-kabir-singh-1
Agent guide: https://www.promptabide.com/llms.txt · https://www.promptabide.com/agent-instructions.md
Sitemap: https://www.promptabide.com/sitemap.xml
