Skip to content

refactor: extract shared EnsureSuccessAsync helper#46

Merged
rubenhensen merged 1 commit into
mainfrom
refactor/shared-ensure-success
Jul 22, 2026
Merged

refactor: extract shared EnsureSuccessAsync helper#46
rubenhensen merged 1 commit into
mainfrom
refactor/shared-ensure-success

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Closes #45

PkgClient and CryptifyClient each carried a private EnsureSuccessAsync with byte-for-byte identical bodies. This moves that logic into one place.

What changed

  • Added src/Api/HttpResponseExtensions.cs with an internal EnsureSuccessAsync extension on HttpResponseMessage.
  • Removed the duplicated private method from both clients; call sites now read await response.EnsureSuccessAsync().

Behaviour is identical: a non-success status still throws NetworkException carrying the status code, upstream body, and request URL.

Tests

  • Existing non-success tests for both clients still pass, exercising the extracted helper through both call sites.
  • Added HttpResponseExtensionsTests covering success, non-success, and the <unknown> URL fallback when RequestMessage is null (a branch the client tests do not reach).
  • dotnet build clean on net8.0 and net10.0 (0 warnings); 82 tests pass on net10.0. Per CLAUDE.md the net8.0 runtime is absent in this workspace, so tests ran on net10.0 only; CI exercises both.

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>
@dobby-coder
dobby-coder Bot requested a review from rubenhensen July 21, 2026 23:36

@dobby-coder dobby-coder Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • PkgClient correctly drops using E4A.PostGuard.Exceptions; — nothing else in that file references the namespace after the move.
  • CryptifyClient correctly keeps the using because it still throws PostGuardException.
  • 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 #45 present, reviewer assigned.

No blocking or style issues. Approved.

@dobby-coder
dobby-coder Bot marked this pull request as ready for review July 21, 2026 23:40
@rubenhensen
rubenhensen merged commit 677c21f into main Jul 22, 2026
2 checks passed
@rubenhensen
rubenhensen deleted the refactor/shared-ensure-success branch July 22, 2026 08:18
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.

Deduplicate EnsureSuccessAsync across PkgClient and CryptifyClient

1 participant