Skip to content

Commit be5d47b

Browse files
Remove try/catch
1 parent b0b3570 commit be5d47b

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

stream-android-core/src/main/java/io/getstream/android/core/api/StreamClient.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ import io.getstream.android.core.api.socket.monitor.StreamHealthMonitor
4242
import io.getstream.android.core.api.subscribe.StreamSubscription
4343
import io.getstream.android.core.api.subscribe.StreamSubscriptionManager
4444
import io.getstream.android.core.internal.client.StreamClientImpl
45-
import io.getstream.android.core.internal.http.interceptor.StreamApiKeyInterceptor
46-
import io.getstream.android.core.internal.http.interceptor.StreamAuthInterceptor
47-
import io.getstream.android.core.internal.http.interceptor.StreamConnectionIdInterceptor
4845
import io.getstream.android.core.internal.serialization.StreamCompositeEventSerializationImpl
4946
import io.getstream.android.core.internal.serialization.StreamCompositeMoshiJsonSerialization
5047
import io.getstream.android.core.internal.serialization.StreamMoshiJsonSerializationImpl
@@ -55,7 +52,6 @@ import kotlinx.coroutines.Job
5552
import kotlinx.coroutines.SupervisorJob
5653
import kotlinx.coroutines.flow.MutableStateFlow
5754
import kotlinx.coroutines.flow.StateFlow
58-
import okhttp3.OkHttpClient
5955

6056
/**
6157
* Entry point for establishing and managing a connection to Stream services.
@@ -263,13 +259,13 @@ fun StreamClient(
263259
httpBuilder.apply {
264260
addInterceptor(StreamOkHttpInterceptors.clientInfo(clientInfoHeader))
265261
addInterceptor(StreamOkHttpInterceptors.apiKey(apiKey))
266-
addInterceptor(StreamOkHttpInterceptors.auth( "jwt", tokenManager, compositeSerialization))
262+
addInterceptor(
263+
StreamOkHttpInterceptors.auth("jwt", tokenManager, compositeSerialization)
264+
)
267265
addInterceptor(StreamOkHttpInterceptors.connectionId(connectionIdHolder))
268266
}
269267
}
270-
configuredInterceptors.forEach {
271-
httpBuilder.addInterceptor(it)
272-
}
268+
configuredInterceptors.forEach { httpBuilder.addInterceptor(it) }
273269
}
274270

275271
return StreamClientImpl(

stream-android-core/src/main/java/io/getstream/android/core/api/model/config/StreamHttpConfig.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package io.getstream.android.core.api.model.config
217

318
import okhttp3.Interceptor
@@ -13,5 +28,5 @@ import okhttp3.OkHttpClient
1328
data class StreamHttpConfig(
1429
val httpBuilder: OkHttpClient.Builder,
1530
val automaticInterceptors: Boolean = true,
16-
val configuredInterceptors: Set<Interceptor> = emptySet()
17-
)
31+
val configuredInterceptors: Set<Interceptor> = emptySet(),
32+
)

stream-android-core/src/main/java/io/getstream/android/core/internal/serialization/StreamCompositeEventSerializationImpl.kt

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,30 @@ internal class StreamCompositeEventSerializationImpl<T>(
9898
fun deserialize(raw: String): Result<StreamCompositeSerializationEvent<T>> =
9999
runCatchingCancellable {
100100
val type = peekType(raw)
101-
return try {
102-
when (type) {
103-
null -> {
104-
val ext = external
105-
ext.deserialize(raw).map { StreamCompositeSerializationEvent.external(it) }
106-
}
107-
in alsoExternal -> {
108-
val coreSer = internal
109-
val extSer = external
110-
val core = coreSer.deserialize(raw).getOrThrow()
111-
val prod = extSer.deserialize(raw).getOrThrow()
112-
Result.success(StreamCompositeSerializationEvent.both(core, prod))
113-
}
114-
in internalTypes -> {
115-
val coreSer = internal
116-
coreSer.deserialize(raw).map {
117-
StreamCompositeSerializationEvent.internal(it)
118-
}
119-
}
120-
else -> {
121-
val ext = external
122-
ext.deserialize(raw).map { StreamCompositeSerializationEvent.external(it) }
123-
}
101+
when (type) {
102+
null -> {
103+
val ext = external
104+
ext.deserialize(raw).map { StreamCompositeSerializationEvent.external(it) }
124105
}
125-
} catch (e: Throwable) {
126-
Result.failure(e)
127-
}
106+
107+
in alsoExternal -> {
108+
val coreSer = internal
109+
val extSer = external
110+
val core = coreSer.deserialize(raw).getOrThrow()
111+
val prod = extSer.deserialize(raw).getOrThrow()
112+
Result.success(StreamCompositeSerializationEvent.both(core, prod))
113+
}
114+
115+
in internalTypes -> {
116+
val coreSer = internal
117+
coreSer.deserialize(raw).map { StreamCompositeSerializationEvent.internal(it) }
118+
}
119+
120+
else -> {
121+
val ext = external
122+
ext.deserialize(raw).map { StreamCompositeSerializationEvent.external(it) }
123+
}
124+
}.getOrThrow()
128125
}
129126

130127
private fun peekType(raw: String): String? {

0 commit comments

Comments
 (0)