mirror of
https://github.com/Comfy-Org/comfy-swift-sdk.git
synced 2026-11-04 23:47:26 +00:00
[PR #28] [MERGED] refactor(transport): extract shared send() + api/view URL builder #30
Labels
No labels
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-swift-sdk#30
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-swift-sdk/pull/28
Author: @mattmillerai
Created: 7/4/2026
Status: ✅ Merged
Merged: 7/5/2026
Merged by: @mattmillerai
Base:
main← Head:refactor/transport-send-helper📝 Commits (2)
a844213refactor(transport): extract shared send() + api/view URL builder2964237fix(transport): bound + clean up the download error-body read; preserve poll retry semantics📊 Changes
2 files changed (+200 additions, -81 deletions)
View changed files
📝
Sources/ComfySwiftSDK/Internal/Transport.swift(+95 -81)➕
Tests/ComfySwiftSDKTests/DownloadViewErrorBodyTests.swift(+105 -0)📄 Description
ELI-5
Six of the
Transportrequest methods each hand-wrote the same little dance: fire the request, translate any transport error, peek at the body on a 400/422 to turn it into a friendly error, then check the status code. This PR pulls that repeated tail into one tinysend(_:)helper and gives the twoapi/viewdownload methods a shared URL builder — so the plumbing lives in one place instead of six.Along the way it fixes a real bug: the video download path (
downloadViewToTempFile) was the one place that forgot the 400/422 body check, so a rejected video download surfaced a generic.networkerror instead of the same.serverRejectedreason the image path gives you. Now both agree.What changed
private func send(_ request:) -> (Data, URLResponse)— wrapssession.data(for:)+translate+ the 400/422checkBodyguard +checkStatus. The fivesession.data-based endpoints (uploadImage,submitPrompt,validateAuth,fetchJobStatus,downloadView) now route through it.private func viewURL(filename:subfolder:type:)— the identicalapi/viewURL-composition block the two download methods duplicated, now shared (still fails fast on a malformed URL).applyAuthis still called by each method beforesend; response decoding stays in each method.downloadViewToTempFilekeeps its ownsession.download(for:)call (it streams to a temp file and can't sharesend), but now mirrors the 400/422checkBodyby reading the small error payload back off disk — closing the inconsistency withdownloadView.cancelJob(deliberately swallows errors viatry?).Net: ~60 lines of duplicated HTTP tail removed, two focused helpers added.
Judgment calls
validateAuthandfetchJobStatusnow also run the 400/422checkBody(previously only 3 of the methods did). This is the natural consequence of a single shared helper and is strictly more informative — a 400/422 on those endpoints now surfaces a.serverRejectedreason instead of a generic.network(badServerResponse). It never turns an error into a success (on 400/422,checkBodyeither throws a more specific error or falls through to the samecheckStatusfailure as before).Tests
DownloadViewErrorBodyTests: assertsdownloadViewToTempFilenow maps a 400 error body to.serverRejected(the closed gap), thatdownloadViewstill does the same, and that the temp-file happy path still returns the file on a 200.swift test --no-parallel): 153 tests, 21 suites (2 live smoke tests skipped as designed).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.