Skip to content

feat: production-ready error handling (prefixed codes, domain errors, global filter, structured logging) - #14

Merged
lmoraesdev merged 7 commits into
mainfrom
feat/production-ready-error-handling
May 24, 2026
Merged

feat: production-ready error handling (prefixed codes, domain errors, global filter, structured logging)#14
lmoraesdev merged 7 commits into
mainfrom
feat/production-ready-error-handling

Conversation

@lmoraesdev

Copy link
Copy Markdown
Owner

Summary

  • Error codes prefixados: CHARGE_NOT_FOUNDAE01, IDEMPOTENCY_CONFLICTAE02, INVALID_STATE_TRANSITIONAE03, WEBHOOK_EVENT_ALREADY_PROCESSEDAE04, mais dois novos: AE05 (UNKNOWN_EVENT_TYPE) e AE06 (MISSING_IDEMPOTENCY_KEY), e IE01 (INTERNAL_ERROR) para erros inesperados
  • Novos DomainErrors: UnknownEventTypeError e MissingIdempotencyKeyError substituem throw new Error(...) e throw new BadRequestException(...) hardcoded
  • Logging 5W1H no DomainExceptionFilter: todo erro de domínio capturado emite logger.warn com what, why (code), how (method + url), error_class e message
  • GlobalExceptionFilter: captura erros inesperados (não-DomainError), loga com stack trace e responde sempre com { statusCode: 500, code: "IE01", message: "Internal server error" } — zero vazamento de detalhes internos
  • try/catch nos services: CreateChargeService e ProcessWebhookService relançam DomainError sem log (o filter cuida) e logam + relançam erros inesperados com contexto (charge_id, event_id)
  • Testes: 2 novos spec files (domain-errors.spec.ts, domain-exception.filter.spec.ts), testes e2e atualizados — 102 testes passando

Test plan

  • npm test — 102 passed, 0 failed
  • npm run build — build limpo, sem erros TypeScript
  • Erros de domínio retornam code no formato AExx (ex: AE01 para 404, AE02 para 422)
  • Erros inesperados retornam { statusCode: 500, code: "IE01", message: "Internal server error" } sem vazar detalhes
  • Logs de domínio aparecem com level: warn, campo why com o código e how com METHOD /path

@lmoraesdev
lmoraesdev merged commit d691911 into main May 24, 2026
1 check passed
@lmoraesdev
lmoraesdev deleted the feat/production-ready-error-handling branch May 24, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant