refactor(data): extract shared guardedApiCall for API-backed repositories#31
Merged
Conversation
…ries NewsRepositoryImpl and GeminiAssistantRepository duplicated the same guard sequence: short-circuit on a blank credential, then runCatching the remote call and log failures under the repo tag. Pull it into one inline `guardedApiCall` helper in `data/ApiCall.kt` so both repositories share a single implementation and any future API-backed repository inherits the same behavior. Behavior is unchanged: blank keys still fail fast without a network call, and exceptions still collapse to Result.failure with a logged stack trace.
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
NewsRepositoryImplandGeminiAssistantRepositoryeach repeated the same guard sequence around their remote call: short-circuit to a failedResultwhen the API key is blank (logging the reason), then wrap the call inrunCatchingand log any failure under the repo tag. This PR extracts that sequence into a singleinline fun guardedApiCall(...)indata/ApiCall.ktand routes both repositories through it.Rationale
The two repositories had drifted into the same boilerplate. Centralizing it removes the duplication (DRY) and gives any future API-backed repository the same fail-fast-on-blank-key plus logged-failure behavior without re-implementing it. The helper is
inlineso theblocklambda can still call the repositories' ownsuspendfunctions.Behavior is preserved: blank keys still fail without touching the network, and exceptions still collapse to
Result.failurewith a full stack trace in logcat. Only the blank-key log wording changed slightly.Verification
./gradlew ktlintCheck detekt testDebugUnitTest-> BUILD SUCCESSFUL./gradlew assembleDebug-> BUILD SUCCESSFULTest plan
Checklist
refactor/).[Unreleased]. (No user-visible change.)