Skip to content

Commit

Permalink
cleaned up some sync code
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Oct 23, 2024
1 parent 0348b6d commit a0d0583
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalContracts::class)

package com.nononsenseapps.feeder.sync

import android.util.Log
Expand All @@ -24,7 +22,6 @@ import org.kodein.di.instance
import retrofit2.Response
import java.net.URL
import java.time.Instant
import kotlin.contracts.ExperimentalContracts

class SyncRestClient(override val di: DI) : DIAware {
private val repository: Repository by instance()
Expand Down Expand Up @@ -605,14 +602,15 @@ class SyncRestClient(override val di: DI) : DIAware {

private suspend fun ErrorResponse.leaveChainIfKickedOutElseLog() {
Log.e(LOG_TAG, "leaveChainIfKickedOutElseLog: $code, $body", throwable)
if (code == 400 && body?.contains("Device not registered", ignoreCase = true) == true) {
// Forbidden, this device has been removed from the chain from another device
if (body?.contains(DEVICE_NOT_REGISTERED, ignoreCase = true) == true) {
// this device has been removed from the chain from another device
leave()
}
}

companion object {
private const val LOG_TAG = "FEEDER_REST_CLIENT"
private const val DEVICE_NOT_REGISTERED = "Device not registered"
}
}

Expand Down

0 comments on commit a0d0583

Please sign in to comment.