Repository navigation
Replace exception-based error handling with a Result/Error pattern across the API - #113
Merged
Merged
Conversation
- Introduce `Result` and `Result<T>` to represent success or failure states in operations. - Define `Error` class with `ErrorType` enumeration for structured error handling.
- Implement extension methods `ToActionResult` and `ToActionResult<T>` for mapping `Result` and `Result<T>` to appropriate HTTP responses. - Introduce internal `Problem` method for structured error handling based on `ErrorType`.
…ized operation outcomes and update controllers accordingly.
… refactor controllers accordingly
…e controllers for standardized responses
…lated tests and Result extension
…ardization for API responses - Update command and query handlers to return `Result` or `Result<T>` types consistently. - Enhance `ToActionResult` extension with action name support for improved response construction. - Adjust controllers to leverage `ToActionResult` for standardized and structured API responses. - Refactor related tests to align with updated response structures.
…om `Value`-based responses to standardized `Result` types - Update command handlers, models, and tests to return `Result` or `Result<T>` for consistent API response handling. - Replace `Value` with `Id` in response models (e.g., `CreateItemResponse`, `AddZoneResponse`) and adjust all references/test cases. - Extend `ToActionResult` to support flexible value selectors and improve response generation. - Standardize error handling across operations with the `Result`-based approach, modifying controllers to leverage updated handlers. - Refactor tests to align with the new `Result` pattern and simplified response models.
…tandardized response handling and update controllers with `ToActionResult` integration
…tandardized response handling and update controllers with `ToActionResult` integration
… exception-to-resul-pattern
…onsistent response standardization and integrate `ToActionResult` in controllers.
…onsistent response standardization and integrate `ToActionResult` in controllers.
… for standardized response handling and integrate `ToActionResult` in controllers.
… exception-to-resul-pattern # Conflicts: # Nimbo.Wms/Controllers/Documents/AdjustmentDocumentsController.cs
… Result pattern Mirrors the Adjustment/CycleCount conversion already on this branch: - Commands/queries return Result / Result<T> instead of throwing NotFoundException/ConcurrencyException. - Handlers return Error.NotFound/Error.Conflict instead of throwing. - Controllers use ToActionResult(this) instead of raw DTOs/NoContent, matching the ProblemDetails contract. Covers ReceivingDocument(Lines), RelocationDocument(Lines), ShipmentDocument(Lines), ShipmentPickLines, and ChangeCustomer for full bounded-context consistency. Also fixed a pre-existing copy/paste bug in Receiving/Relocation Patch handlers where the Title branch called ChangeCode instead of ChangeTitle. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K3RVvP61dDJgVjGcA4H5oS
…ndlers and controllers to adopt `Result` pattern for consistent error handling and response generation.
…rn for consistent error handling and standardized response generation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Introduces
Result/Result<T>(Nimbo.Wms.Contracts/Result.cs) and anErrorvalue type withErrorType(NotFound, Conflict, Validation, BusinessRule, Unexpected), plus aToActionResultextension (
Nimbo.Wms/Extensions/ResultExtensions.cs) that maps aResultto the rightProblemDetailsstatus code.Every command/query handler across the API now returns
Result/Result<T>instead of throwingNotFoundException/ConcurrencyExceptionfor expected failure paths (not-found, versionconflicts), and every controller action returns
result.ToActionResult(this)instead of rawDTOs/
NoContent()/an unguarded throw.Scope
Converted end-to-end: MasterData (Items, Suppliers), Topology (Warehouses, Zones, Locations),
Stock (InventoryItems), and Documents — Adjustment, CycleCount, Receiving, Relocation, Shipment
(including lines and Shipment's pick-lines/change-customer endpoints).
Why
Exceptions for expected outcomes (a document that doesn't exist, an optimistic-concurrency
mismatch) made control flow and status-code mapping implicit and scattered across a global
exception middleware.
Resultmakes failure an explicit, typed return value handlers andcontrollers both reason about directly, and keeps the HTTP status mapping in one place
(
ResultExtensions).Notes
Fixed two pre-existing copy/paste bugs surfaced while porting Receiving/Relocation's Patch
handlers: the Title branch was calling
ChangeCodeinstead ofChangeTitle.Testing
dotnet build— 0 errors.dotnet test(unit + integration, Docker/Testcontainers) — all passing.