Skip to content

feat: add ExceptionHandlingBehavior to centralize error handling - #5

Open
Mehrdad-Sohayl wants to merge 1 commit into
amirhossein-tohidi:mainfrom
Mehrdad-Sohayl:feature/exception-handling-behavior
Open

feat: add ExceptionHandlingBehavior to centralize error handling#5
Mehrdad-Sohayl wants to merge 1 commit into
amirhossein-tohidi:mainfrom
Mehrdad-Sohayl:feature/exception-handling-behavior

Conversation

@Mehrdad-Sohayl

Copy link
Copy Markdown

Summary

Adds ExceptionHandlingBehavior MediatR pipeline behavior to centralize exception handling in command handlers.

Changes

  • New: src/Wallet.Application/Common/Behaviors/ExceptionHandlingBehavior.cs - Pipeline behavior that intercepts:
    • FluentValidation errors → Result.Failure
    • Business rule violations (InvalidOperationException with specific messages) → Result.Failure
    • Concurrency conflicts (DbUpdateConcurrencyException) → Result.Failure with standard message
    • Re-throws if response type isn't Result<T>
  • Modified: src/Wallet.Application/DependencyInjection.cs - Added DI registration

Benefits

  • Eliminates duplicate try/catch blocks in 8+ command handlers (TopUpWallet, FastPay, Reserve, ConfirmReservation, CancelReservation, Refund, ConsumePromo, AddPromoGrant)
  • Centralized error handling logic
  • Consistent error responses
  • Cleaner handlers focused on business logic

Testing

  • All 143 existing tests pass (Unit: 111, Integration: 11, Acceptance: 11, Property: 5, Architecture: 5)
  • Build succeeds with 0 warnings/errors

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