Skip to content

Commit

Permalink
修改retrofit版本号补提
Browse files Browse the repository at this point in the history
  • Loading branch information
neilyhe committed Oct 16, 2024
1 parent 926b915 commit 34e52f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class StringRequest private constructor() {
callback.success(response.body(), reqCode)
} else {
L.d(TAG, "请求成功:${response.errorBody()}")
callback.success(response.errorBody().string(), reqCode)
callback.success(response.errorBody()?.string(), reqCode)
}
}
})
Expand Down Expand Up @@ -123,7 +123,7 @@ class StringRequest private constructor() {
callback.success(response.body(), reqCode)
} else {
L.d(TAG, "请求成功:${response.errorBody()}")
callback.success(response.errorBody().string(), reqCode)
callback.success(response.errorBody()?.string(), reqCode)
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ class StringRequest private constructor() {
callback.success(response.body(), reqCode)
} else {
L.d(TAG, "请求成功:${response.errorBody()}")
callback.success(response.errorBody().string(), reqCode)
callback.success(response.errorBody()?.string(), reqCode)
}
}

Expand Down Expand Up @@ -187,7 +187,7 @@ class StringRequest private constructor() {
callback.success(response.body(), reqCode)
} else {
L.d(TAG, "请求成功:${response.errorBody()}")
callback.success(response.errorBody().string(), reqCode)
callback.success(response.errorBody()?.string(), reqCode)
}
}

Expand Down Expand Up @@ -235,7 +235,7 @@ class StringRequest private constructor() {
callback.success(response.body(), reqCode)
} else {
L.d(TAG, "请求成功:${response.errorBody()}")
callback.success(response.errorBody().string(), reqCode)
callback.success(response.errorBody()?.string(), reqCode)
}
}

Expand Down Expand Up @@ -276,7 +276,7 @@ class StringRequest private constructor() {
callback.success(response.body(), reqCode)
} else {
L.d(TAG, "请求成功:${response.errorBody()}")
callback.success(response.errorBody().string(), reqCode)
callback.success(response.errorBody()?.string(), reqCode)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ class StringCallAdapterFactory private constructor() : CallAdapter.Factory() {
type: Type?,
array: Array<out Annotation>?,
retrofit: Retrofit?
): CallAdapter<*>? {
): CallAdapter<Any, String>? {
if (type == String::class.java)
return StringCallAdapter()
return null
}

inner class StringCallAdapter : CallAdapter<String> {
override fun <R : Any?> adapt(call: Call<R>?): String {
inner class StringCallAdapter : CallAdapter<Any, String> {
override fun responseType(): Type {
return String::class.java
}

override fun adapt(call: Call<Any>): String {
try {
return call?.execute()?.body().toString()
return call.execute().body().toString()
} catch (e: Exception) {
e.printStackTrace()
}
return ""
}

override fun responseType(): Type {
return String::class.java
}
}

companion object {
Expand Down

0 comments on commit 34e52f2

Please sign in to comment.