chore: simplify http/response memoization, docs, and exception constructors#187
Merged
Merged
Conversation
…uctors Three self-contained cleanups in the http/response subsystem, none of which changes runtime behavior: - ParsedResponse: replace the bespoke private Outcome sealed class with a memoized kotlin.Result. runCatching/getOrThrow preserve the exact Throwable-catching and memoize-before-throw semantics, and a nullable Result<T>? keeps the deliberate null-success vs. unparsed distinction. - ResponseBody: rewrite the class KDoc around the real source(): BufferedSource contract (it previously described byteStream/bytes/string methods the type never declared) and drop the now-unused java.io.InputStream import. - HttpException: add one protected constructor that unpacks status/headers/body from a Response, and collapse the 18 subclasses' identical six-argument delegation blocks to a single-line delegation. Subclass public constructor surfaces are unchanged; the new protected constructor is reflected in the committed API snapshot.
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.
Summary
Three small, self-contained cleanups in the
http/responsesubsystem. None changes runtime behavior — each reuses a stdlib primitive, fixes stale documentation, or removes copy-pasted boilerplate.1.
ParsedResponse— memoize withkotlin.ResultThe class hand-rolled a private
Outcomesealed class (Success/Failure) purely to memoize the handler's result-or-throw. That is exactly whatkotlin.Resultmodels, and the module already usesrunCatching/getOrThrowelsewhere. Storing the memo as a nullableResult<T>?keeps the deliberate "null success vs. not-yet-parsed" distinction, andrunCatchingcatchesThrowable(not justException), so the existing semantics — including memoizing anErrorso a later call can't re-read the single-use body — are preserved exactly. Call sites are unchanged.2.
ResponseBody— align the class KDoc with the real contractThe class KDoc described a
byteStream/bytes/stringAPI that this type never declared; its only read accessor issource(): BufferedSource. The doc was also the sole reference tojava.io.InputStream, so it dragged along an unused import (whichktlint'sno-unused-importsrule underallWarningsAsErrorswould flag once the doc stopped mentioning it). The KDoc now describes the actualsource()contract and the import is removed.3.
HttpException— funnel the 18 subclass constructors through one base constructorEach of the 18 concrete subclasses repeated the same six-argument block unpacking
response.status/response.headers/response.bodyinto the base constructor. Hoisting that into a singleprotectedconstructor that takes theResponsedirectly collapses every subclass to a one-line delegation. The subclasses' public(response, message?, cause?, value?)surfaces are byte-for-byte unchanged.API impact
Adds one
protectedconstructor toHttpException; the regeneratedsdk-core.apisnapshot is committed. No public signatures change.Verification
./gradlew :sdk-core:buildpasses — tests, ktlint, detekt,apiCheck, and the coverage gate.Closes #175