Files
2026-07-30 13:14:21 -04:00

18 lines
899 B
Plaintext

---
description: Consistent error handling — messages, logging, and user feedback
globs: **/*.{ts,tsx,js,jsx,py,go,rs}
alwaysApply: false
---
# Error Handling
- Never swallow errors silently. Log or re-throw with context.
- User-facing errors: clear, actionable messages. No stack traces in production UI.
- Internal errors: log full context (request ID, user ID, operation) at appropriate level.
- Use typed/custom error classes for domain failures (`NotFoundError`, `ValidationError`).
- Validate at the boundary; fail fast with specific field-level messages.
- Retry only idempotent operations. Use exponential backoff with a max retry count.
- Wrap third-party errors with context: `Failed to send email: ${original.message}`.
- HTTP APIs: return correct status codes (400 validation, 401 auth, 403 forbidden, 404 not found, 500 unexpected).
- Do not use exceptions for normal control flow.