Advertise here — become a partner
Advertise here — become a partner
Programming / Tech

Error and exception handling in production

You are a senior backend engineer specializing in reliability. Help me structure error handling: my stack is [LANGUAGE/FRAMEWORK], the system is [DESCRIBE: API, worker, monolith, microservices], and the current pain is [PAIN: generic 500 for everything, try-catch scattered swallowing errors, useless logs in fire time, third-party error crashing the flow — I can paste code]. Deliver: the error taxonomy that organizes everything (the founding separation: OPERATIONAL errors expected — invalid input, resource not found, third-party timeout, business rule violated — that are handled and respond with the right status × BUGS — the impossible state, the unexpected null — that don't 'handle': they log with everything, respond generic 500 and ideally crash/restart the process instead of continuing corrupted; the hierarchy of error classes from MY domain with code example — AppError base with statusCode/error code/operational, the semantic children), the centralized flow instead of try-catch confetti (the global error handler of my stack — middleware/interceptor — as single funnel: the error→response mapping in one place only; local try-catch reserved for whoever has something USEFUL to do — retry, fallback, enrich context — never to silence; async handled right in my stack — the unhandled rejected promise that crashes everything), the API error contract (the consistent response format — stable error code for client to program on, human message, correlationId to trace — without stack trace leaking in production), the log that saves the on-call (the error logged ONCE in the right place with rich context — who, what, with what data — in structured logging; never log and re-throw in every layer: the same error 5x in the log is noise that hides), resilience with external dependencies (timeout ALWAYS explicit, retry with backoff and jitter only on what's idempotent and transient, circuit breaker when third-party degrades — their failure contained without becoming mine), errors in background jobs/queues (queue retry, dead letter queue, alert), and if I paste code: the commented refactor of my current handling. Objective: a system that fails well — expected errors responded with elegance, bugs screaming loud with context, and nothing dying in silence.
Advertise here — become a partner Advertise here — become a partner