Skip to content

Commit b27634c

Browse files
committed
fix: Fix type inference errors caused by upgrading Kotlin version
1 parent 9a39e03 commit b27634c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/kotlin/com/haroldadmin/cnradapter/CoroutinesNetworkResponseAdapter.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import java.lang.reflect.Type
1616
* @param errorConverter The converter to extract error information from [ResponseBody]
1717
* @constructor Creates a CoroutinesNetworkResponseAdapter
1818
*/
19+
20+
private const val UNKNOWN_ERROR_RESPONSE_CODE = 520
21+
1922
internal class CoroutinesNetworkResponseAdapter<T : Any, U : Any>(
2023
private val successBodyType: Type,
2124
private val errorConverter: Converter<ResponseBody, U>
@@ -51,9 +54,9 @@ internal class CoroutinesNetworkResponseAdapter<T : Any, U : Any>(
5154

5255
is HttpException -> {
5356
// Try to extract the error body
54-
val error = throwable.response().errorBody()
55-
val responseCode = throwable.response().code()
56-
val headers = throwable.response().headers()
57+
val error = throwable.response()?.errorBody()
58+
val responseCode = throwable.response()?.code() ?: UNKNOWN_ERROR_RESPONSE_CODE
59+
val headers = throwable.response()?.headers()
5760
val errorBody = when {
5861
error == null -> null // No error content available
5962
error.contentLength() == 0L -> null // Error content is empty

0 commit comments

Comments
 (0)