Send one problem response per Error everywhere: controllers match minimal APIs, and exceptions that carry an error get its status - #425
Merged
Conversation
…imal APIs, and exceptions that carry an error get its status
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.
Summary
Builds every error response in one module of
Vulthil.SharedKernel.Api, so the sameErrorgets the same responseon every path, and an exception that carries an
Erroris answered like a failed result with that error.Before (checked on a real host):
ToIResult): the full RFC 7807 body —type,title,status,detail,instance, the code,traceId,requestId.ToActionResult): a rawObjectResultthat skipped the problem-details service, so the body had onlystatus,detailand the code. Validation errors went throughValidationProblem()and had nodetail.GlobalExceptionHandler: one generic 500 for every exception — including aDomainExceptionthat carries anError.Conflict, and FluentValidation'sValidationExceptionthrown for commands that do not return aResult.result-pattern.mdclaimed both paths give "the same status and detail", which was false for validation errors.Change
Vulthil.Results: new publicIHasError(Error Error { get; }), a type that carries anError.Vulthil.SharedKernel:DomainExceptionimplementsIHasError.Vulthil.SharedKernel.Application: new publicCommandValidationException : FluentValidation.ValidationException, IHasError. The validation pipeline behavior throws it for commands that do not return aResult; it carries thesame
ValidationErrora failed result would. Code that catchesValidationExceptionkeeps working.Vulthil.SharedKernel.Api:CustomResults.CreateProblemDetails) creates every error's problem body.ToActionResultruns the sameProblemHttpResultas the minimal-API path, through an internalIActionResultadapter, so controllers send identical bodies. It no longer writes into
ModelState.GlobalExceptionHandleranswers anIHasErrorexception with its error's problem response (a Conflict gives409, a validation error gives 400) and logs it at Warning when the status is 4xx. Every other exception keeps the
generic 500 without its message, logged at Error.
result-pattern.md(fixed claim, new "Exceptions that carry an error" section),domain-modeling.md,cqrs-pipeline.md, and the Results, SharedKernel, Application and Api package pages.Behavior changes for consumers
type,title,instance,traceIdandrequestId; controller validation bodiesgain
detail.DomainExceptiongets its error's status instead of 500.Resultgets 400 instead of 500.IHasErrorandCommandValidationException.Verification
Vulthil.IntegrationTests(68 tests) and the Aspiremessaging integration tests (13 tests).
ProblemResponseTests(9 tests) send real requests through a test server. This addsMicrosoft.AspNetCore.TestHoston the$(FrameworkVersion)train and to Dependabot's ignore list. They pin:DomainExceptiongets the same body as a failed result (409);CommandValidationExceptiongets the same 400 validation body as a failed result;ObjectResultfails 40 tests, 3 of them end-to-end.dotnet packof the four changed packages passes package validation against the 1.2.0 baseline.Backport to v1.0: no