Repository navigation
Conversation
Contributor
|
Thanks @AtakanUk, this is a solid fix and the tests are thorough. I'm closing this PR so I can rework it on a new branch built on your commit. There is an existing internal |
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.
Fixes #2368
ApiException.Createturns aproblem+jsonresponse into aValidationApiExceptionthrough the configured serializer. With a source-generated context (includingRefitSettings.ForJsonContext), or in a trimmed or Native AOT app, that read throws, the failure is swallowed, and the caller gets a plainApiException.Changes in
ValidationApiException:CreateAsyncstill tries the configured serializer first, so fix: ValidationApiException propagates ContentHeaders and uses configured serializer #2146 keeps working. If it throwsNotSupportedExceptionorInvalidOperationException, the content is read withDeserializeProblemDetails, which needs no metadata. AJsonExceptionmeans the body itself was rejected, so that case stays a plainApiException, as it does today.DynamicDependencykeeps theProblemDetailsconstructor and properties. The fallback alone isn't enough: it makes the constructor reachable, so the reflection path stops throwing in a trimmed app and returns an empty result. In a published Blazor WebAssembly app this gave aValidationApiExceptionwith noErrorsand noExtensions.RequestContent. Otherwise clients that used to get a plainApiExceptionwould lose them. This also applies to responses that already became aValidationApiException.The
ErrorsandContextClientSampledocumentation samples no longer need the manual parse, so they now catchValidationApiException.Things worth checking in review:
ValidationApiException.Create: non-objecterrorsare ignored, and a body it can't read, such as"status":"400", stays a plainApiException.XmlContentSerializerclients now get aValidationApiExceptionforproblem+jsontoo. Newtonsoft results are unchanged.ExceptionRedactorcan't clear the parsedValidationApiException.Content. Default clients already work this way, but context clients now reach that path too.ProblemDetails, so that case only uses the fallback on earlier targets.Keeping the swallowed failure visible (the second suggestion in the issue) is not part of this PR.
Tests: unit tests in
ApiExceptionTests.ProblemDetailsFallback.csand a problem reply inRefit.NativeAotSmoke, which fails without the fix. TheDynamicDependencyhas no automated test, because the smoke app has no reflection path. I checked it by hand withPublishTrimmedconsole apps on .NET 8, 9 and 10, and a published Blazor WebAssembly app run in headless Edge.