Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Dec 21, 2023
1 parent 0867276 commit 050110e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions retrofit/src/main/java/retrofit2/ResultCallAdapterFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class ResultCallAdapterFactory private constructor() : CallAdapter.Factory() {
annotations: Array<Annotation>,
retrofit: Retrofit
): CallAdapter<*, *>? {
if (getRawType(returnType) != Result::class.java) {
return null
}
if (getRawType(returnType) != Result::class.java) return null

check(returnType is ParameterizedType) {
"Result must have a generic type (e.g., Result<T>)"
Expand Down Expand Up @@ -45,7 +43,7 @@ class ResultCall<T>(private val delegate: Call<T>) : Call<Result<T>> {
override fun onResponse(call: Call<T>, response: Response<T>) {
val result = runCatching {
if (response.isSuccessful) {
response.body() ?: error("Response body is null")
response.body() ?: error("Response $response body is null.")
} else {
throw HttpException(response)
}
Expand All @@ -63,7 +61,7 @@ class ResultCall<T>(private val delegate: Call<T>) : Call<Result<T>> {
val result = runCatching {
val response = delegate.execute()
if (response.isSuccessful) {
response.body() ?: error("Response body is null")
response.body() ?: error("Response $response body is null.")
} else {
throw IOException("Unexpected error: ${response.errorBody()?.string()}")
}
Expand Down

0 comments on commit 050110e

Please sign in to comment.