Refine TypedNetwork API visibility: expose APIClient, internalize MiddlewareChain#5
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32e9eaeb86
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| func send<E: Endpoint>(_ endpoint: E) async throws -> E.Response { | ||
| public func send<E: Endpoint>(_ endpoint: E) async throws -> E.Response { |
There was a problem hiding this comment.
Handle non-2xx responses for Never endpoints
Making send public exposes the existing non-2xx path to downstream clients whose endpoints use the protocol default Failure == Never. In that common case, any 4xx/5xx response calls the default Endpoint.mapError, which unconditionally fatalErrors instead of throwing NetworkError, so a public API request can crash the app on an ordinary server error unless every consumer defines a custom failure mapper.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Summary
- Updated
APIClient.send(_:)to guard the non-2xx path for endpoints whoseFailureisNever, so it no longer callsmapError(which previously triggered afatalErrorvia the default implementation). It now throwsNetworkError.endpointwith an internal fallback error instead. - Added a regression test covering a
Failure == Neverendpoint receiving a 500 response, verifying that the client throws instead of crashing. - Committed changes on branch
workwith commit message:Handle non-2xx responses for Never-failure endpoints.
Testing
- ✅
swift test - ✅
git status --short - ✅
git commit -m "Handle non-2xx responses for Never-failure endpoints"
Additionally, I created the follow-up PR message via make_pr summarizing the fix and validation.
Motivation
APIClient) while keeping middleware orchestration internals hidden.Description
APIClienttopublicand make its initializer andsend(_:)methodpublic, and reduce accidental exposure by changingMiddlewareChainfrompublicto internal (removedpublicfrom the type and itsinit). Files modified:Sources/TypedNetwork/APIClient.swift,Sources/TypedNetwork/Middleware.swift.Testing
swift buildandswift test; both succeeded (swift testran the suite and all tests passed).Codex Task