Skip to content

Add ErrorResult.get(mapError:) and expectSuccess(orError:mapError:) - #35

Merged
germ-mark merged 1 commit into
mainfrom
mark/expect-success-or-error
Jul 28, 2026
Merged

Add ErrorResult.get(mapError:) and expectSuccess(orError:mapError:)#35
germ-mark merged 1 commit into
mainfrom
mark/expect-success-or-error

Conversation

@germ-mark

@germ-mark germ-mark commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Stacked on #34 — review that one first; this diff is only the last commit.

Lifts successOrThrow out of oauth4swift, per the review on germ-network/oauth4swift#51, and adds the ErrorResult counterpart the existing callers were hand-rolling.

  • ErrorResult.get(mapError:) — returns the result or throws a mapped error. Both existing consumers (PAR at OAuth+Components.swift:23, token endpoint at :164) already write exactly this switch by hand.
  • expectSuccess(orError:mapError:) — for endpoints with no success body. Kept separate from get rather than folded into it, since going through success would mean passing Data.self as a phantom result type.

Renamed from successOrThrow on the way up: in this struct expect… already means "throws on mismatch" and success… means "returns an ErrorResult", and this throws. The rename also means it can't collide with the internal copy that stays on oauth4swift#51 until that repo picks the new version up.

get deliberately echoes Result.get() — same unwrap-or-throw job — though Swift's takes no argument and throws the contained error rather than mapping one. The argument label keeps them distinguishable at the call site, but unwrap(mapError:) is a reasonable override if it reads wrong.

Both are additive with no call sites until oauth4swift adopts them, so they can share a release with #34 — only #34 can move downstream behavior.

Test notes

swift test green, 25 tests across 7 suites.

🤖 Generated with Claude Code

get(mapError:) replaces the switch that PAR and token-endpoint callers in
oauth4swift hand-roll. expectSuccess(orError:mapError:) covers endpoints with
no success body - lifted from oauth4swift, where token revocation needs it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@germ-mark
germ-mark force-pushed the mark/expect-success-or-error branch from 7985149 to cf1ca2d Compare July 28, 2026 20:05
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cf1ca2d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@germ-network/germ-convenience Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Base automatically changed from mark/fix-success-error-handling to main July 28, 2026 20:26
@germ-mark
germ-mark merged commit d4a4e90 into main Jul 28, 2026
5 checks passed
@germ-mark
germ-mark deleted the mark/expect-success-or-error branch July 28, 2026 20:26
@github-actions github-actions Bot mentioned this pull request Jul 28, 2026
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.

1 participant