JavaScript · Error Handling · Mid-Level · Architecture
How do you distinguish operational errors from programmer errors in a JS service, and how should each be handled?
Short Interview Answer
Operational errors are expected runtime failures (network, validation); programmer errors are bugs. Handle operational, crash/alert on programmer where appropriate.
Detailed Explanation
In Node-ish thinking: operational — retryable HTTP failures, invalid user input — return structured errors to clients. Programmer — `undefined` is not a function — fail fast, log loudly, fix code. Catching programmer errors and continuing can corrupt state. In browsers, show user-friendly messages for operational issues and report bugs to monitoring. Validate inputs at boundaries so core logic can assert invariants. This taxonomy guides whether to catch or throw.
Interview Tip
Reference the operational vs programmer error framing — classic senior Node/JS discussion.
Common Mistake
Catching all errors and continuing as if the process state is fine.