Skip to content

Add GlobalExceptionHandler returning RFC 7807 problem details #45

Description

@tiana-code

Context

GlobalExceptionHandler is a @RestControllerAdvice that catches all typed domain exceptions, Spring validation exceptions, and unexpected exceptions, and maps them to RFC 7807 Problem Details responses (Content-Type: application/problem+json). Every response includes a correlationId from the MDC context.

Acceptance criteria

  • MethodArgumentNotValidException maps to 400 with an errors[] array containing field and code per failing constraint.
  • Typed domain exceptions (NotFoundException, ConflictException, InvariantException) map to 404, 409, 422 respectively.
  • OptimisticLockException after retries exhausted maps to 503.
  • Unhandled exceptions map to 500 without stack trace in the response body (stack trace goes to structured logs only).
  • Every response body includes correlationId matching the X-Correlation-Id response header.

References

Epic E-01 Ledger Foundation. Wiki: Code-Rules, API-Ledger, Architecture-Security.

Definition of Done

Tests green; ktlint and detekt clean; coverage target met; reviewed; SPDX header on new files; no maritime or real-provider names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Critical — blocks release or productionarea:ledgerLedger service (accounts, transactions, balances)effort:M4-16 hourstype:featureNew capability or enhancement

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions