Skip to content

Commit

Permalink
Tweak response.body()
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Dec 21, 2023
1 parent 76b2b67 commit 2a0b56c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions retrofit/src/main/java/retrofit2/ResultCallAdapterFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ResultCall<T>(private val delegate: Call<T>) : Call<Result<T>> {
delegate.enqueue(object : Callback<T> {
override fun onResponse(call: Call<T>, response: Response<T>) {
val result = if (response.isSuccessful) {
Result.success(response.body()!!)
val body = response.body() ?: error("Response body is null")
Result.success(body)
} else {
Result.failure(HttpException(response))
}
Expand All @@ -61,7 +62,8 @@ class ResultCall<T>(private val delegate: Call<T>) : Call<Result<T>> {
return try {
val response = delegate.execute()
val result = if (response.isSuccessful) {
Result.success(response.body()!!)
val body = response.body() ?: error("Response body is null")
Result.success(body)
} else {
Result.failure(IOException("Unexpected error: ${response.errorBody()?.string()}"))
}
Expand Down

0 comments on commit 2a0b56c

Please sign in to comment.