MS-1382 Correct Response handling in backend api client#1620
MS-1382 Correct Response handling in backend api client#1620luhmirin-s merged 3 commits intomainfrom
Conversation
… responses # Conflicts: # infra/event-sync/src/main/java/com/simprints/infra/eventsync/event/remote/EventRemoteDataSource.kt
… error propagation
There was a problem hiding this comment.
Pull request overview
Fixes inconsistent error handling when Retrofit endpoints return Response<T> by ensuring non-2xx responses are treated like regular failed calls (throwing and being mapped consistently), improving reliability of sync/network error behavior across infra modules.
Changes:
- Updated
SimApiClientImplto throwHttpExceptionwhenexecuteCallreturns an unsuccessfulretrofit2.Response<*>. - Added/expanded unit tests covering
Response<T>success/failure paths, retry behavior, and maintenance vs non-maintenance 503 handling. - Updated event-sync remote data source tests to use a lightweight
BackendApiClient+SimNetworkfake instead of wrapping results manually.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| infra/network/src/main/java/com/simprints/infra/network/apiclient/SimApiClientImpl.kt | Ensures unsuccessful Response<*> results throw, enabling consistent exception mapping + retry logic. |
| infra/network/src/test/java/com/simprints/infra/network/apiclient/SimApiClientImplTest.kt | Adds coverage for Response<ResponseBody> and retry/maintenance behavior. |
| infra/network/src/test/java/com/simprints/infra/network/FakeRetrofitInterface.kt | Adds a Retrofit endpoint returning Response<ResponseBody> for testing. |
| infra/backend-api/src/main/java/com/simprints/infra/backendapi/BackendApiClient.kt | Adds an extra response-unwrapping layer and changes constructor visibility. |
| infra/backend-api/src/test/java/com/simprints/infra/backendapi/BackendApiClientTest.kt | Adds tests for Response<ResponseBody> success/failure wrapping (currently with a type-mismatch issue). |
| infra/event-sync/src/test/java/com/simprints/infra/eventsync/event/remote/EventRemoteDataSourceTest.kt | Refactors tests to use a simple BackendApiClient fake path and adds failure-response assertions. |
| infra/event-sync/src/main/java/com/simprints/infra/eventsync/event/remote/EventRemoteDataSource.kt | Minor formatting-only change. |
Comments suppressed due to low confidence (1)
infra/backend-api/src/main/java/com/simprints/infra/backendapi/BackendApiClient.kt:26
- Changing
BackendApiClientfrom@Inject internal constructorto a public@Inject constructorexpands the module’s public API surface. Most infra-layer injected classes keep their constructorsinternalto discourage direct instantiation outside DI (e.g.infra/event-sync/.../DownSyncSubjectUseCase.kt:19,infra/images/.../ImageRepositoryImpl.kt:16). Consider keeping the constructorinternaland adjusting tests to mock/fake at theSimNetwork/SimApiClientlevel (or provide a dedicated test helper) rather than making construction public.
@Singleton
class BackendApiClient @Inject constructor(
private val simNetwork: SimNetwork,
private val authStore: AuthStore,
@param:DeviceID private val deviceId: String,
@param:PackageVersionName private val versionName: String,
) {
infra/backend-api/src/test/java/com/simprints/infra/backendapi/BackendApiClientTest.kt
Show resolved
Hide resolved
infra/network/src/test/java/com/simprints/infra/network/apiclient/SimApiClientImplTest.kt
Outdated
Show resolved
Hide resolved
infra/network/src/test/java/com/simprints/infra/network/apiclient/SimApiClientImplTest.kt
Outdated
Show resolved
Hide resolved
…roved test coverage
49336ab to
d8b7a55
Compare
|
|
Am I correct in my understanding that we shouldn't introduce another type similar to Response or we'll step on the same rake again? |
|
@BurningAXE not exactly. The |



JIRA ticket
Will be released in: 2025.2.1
Root cause analysis (for bugfixes only)
First known affected version: 2024.1.5
Response<T>type, then it will never throw during call execution.Notable changes
Response<ResponseBody>type in the backend API client and unwrapping to follow the same rules as the regular responses - if not successful it is wrapped inApiResponse.Failure()with theSyncCloudIntegrationExceptionas the cause. This should remove the differences in handling of successful and unsuccessful calls in the domain layer.Testing guidance
Additional work checklist