Add interceptors to hebe too
This commit is contained in:
parent
d228df6c6d
commit
57660cc7c9
3 changed files with 20 additions and 6 deletions
|
@ -47,7 +47,11 @@ class Hebe {
|
|||
resettableManager.reset()
|
||||
}
|
||||
|
||||
private val interceptors: MutableList<Pair<Interceptor, Boolean>> = mutableListOf()
|
||||
private val appInterceptors: MutableList<Pair<Interceptor, Boolean>> = mutableListOf()
|
||||
|
||||
fun addInterceptor(interceptor: Interceptor, network: Boolean = false) {
|
||||
appInterceptors.add(interceptor to network)
|
||||
}
|
||||
|
||||
private val serviceManager by resettableLazy(resettableManager) {
|
||||
RepositoryManager(
|
||||
|
@ -55,8 +59,11 @@ class Hebe {
|
|||
keyId = keyId,
|
||||
privatePem = privatePem,
|
||||
deviceModel = deviceModel,
|
||||
interceptors = interceptors,
|
||||
)
|
||||
).apply {
|
||||
appInterceptors.forEach { (interceptor, isNetwork) ->
|
||||
setInterceptor(interceptor, isNetwork)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val routes by resettableLazy(resettableManager) { serviceManager.getRoutesRepository() }
|
||||
|
|
|
@ -18,9 +18,17 @@ internal class RepositoryManager(
|
|||
private val keyId: String,
|
||||
private val privatePem: String,
|
||||
private val deviceModel: String,
|
||||
private val interceptors: MutableList<Pair<Interceptor, Boolean>>,
|
||||
) {
|
||||
|
||||
private val interceptors: MutableList<Pair<Interceptor, Boolean>> = mutableListOf(
|
||||
HttpLoggingInterceptor().setLevel(logLevel) to true,
|
||||
ErrorInterceptor() to false,
|
||||
)
|
||||
|
||||
fun setInterceptor(interceptor: Interceptor, network: Boolean = false) {
|
||||
interceptors.add(0, interceptor to network)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
private val json by lazy {
|
||||
Json {
|
||||
|
@ -62,7 +70,6 @@ internal class RepositoryManager(
|
|||
}
|
||||
.client(
|
||||
OkHttpClient().newBuilder()
|
||||
.addInterceptor(ErrorInterceptor())
|
||||
.apply {
|
||||
if (signInterceptor) {
|
||||
addInterceptor(SignInterceptor(keyId, privatePem, deviceModel))
|
||||
|
|
|
@ -232,7 +232,7 @@ class Sdk {
|
|||
|
||||
fun addInterceptor(interceptor: Interceptor, network: Boolean = false) {
|
||||
scrapper.addInterceptor(interceptor, network)
|
||||
// hebe.setInterceptor(interceptor, network)
|
||||
hebe.addInterceptor(interceptor, network)
|
||||
interceptors.add(interceptor to network)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue