refactor: extract shared EnsureSuccessAsync helper#46
Merged
Conversation
PkgClient and CryptifyClient each carried an identical private EnsureSuccessAsync method. Move it to a single internal HttpResponseExtensions.EnsureSuccessAsync and call it from both. Behaviour is unchanged: same NetworkException with status, upstream body and request URL on a non-success response. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
There was a problem hiding this comment.
VERDICT: approve
Clean refactor — sign-off from Rules Dobby 2.
The private EnsureSuccessAsync was byte-for-byte identical in PkgClient and CryptifyClient; it now lives once in src/Api/HttpResponseExtensions.cs as an internal extension in the same E4A.PostGuard.Api namespace, so both call sites resolve it with no extra using. Behaviour is unchanged: a non-success status still throws NetworkException with status code, upstream body, and request URL.
Verified:
PkgClientcorrectly dropsusing E4A.PostGuard.Exceptions;— nothing else in that file references the namespace after the move.CryptifyClientcorrectly keeps theusingbecause it still throwsPostGuardException.- Tests cover success, non-success (status + URL), and the
RequestMessage == null<unknown>fallback that the client tests don't reach. - Title is conventional-commit format,
Closes #45present, reviewer assigned.
No blocking or style issues. Approved.
rubenhensen
approved these changes
Jul 22, 2026
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.
Closes #45
PkgClientandCryptifyClienteach carried a privateEnsureSuccessAsyncwith byte-for-byte identical bodies. This moves that logic into one place.What changed
src/Api/HttpResponseExtensions.cswith an internalEnsureSuccessAsyncextension onHttpResponseMessage.await response.EnsureSuccessAsync().Behaviour is identical: a non-success status still throws
NetworkExceptioncarrying the status code, upstream body, and request URL.Tests
HttpResponseExtensionsTestscovering success, non-success, and the<unknown>URL fallback whenRequestMessageis null (a branch the client tests do not reach).dotnet buildclean onnet8.0andnet10.0(0 warnings); 82 tests pass onnet10.0. Per CLAUDE.md thenet8.0runtime is absent in this workspace, so tests ran onnet10.0only; CI exercises both.