Browse Source

默认转换器现在要求HTTP状态码为成功才返回数据(泛型Response请求完成都返回)

drake 3 years ago
parent
commit
0ae32b1ae3
1 changed files with 4 additions and 4 deletions
  1. 4 4
      net/src/main/java/com/drake/net/convert/NetConverter.kt

+ 4 - 4
net/src/main/java/com/drake/net/convert/NetConverter.kt

@@ -38,11 +38,11 @@ interface NetConverter {
          */
         override fun <R> onConvert(succeed: Type, response: Response): R? {
             return when {
-                succeed === String::class.java -> response.body?.string() as R
-                succeed === ByteString::class.java -> response.body?.byteString() as R
-                succeed is GenericArrayType && succeed.genericComponentType === Byte::class.java -> response.body?.bytes() as R
+                succeed === String::class.java && response.isSuccessful -> response.body?.string() as R
+                succeed === ByteString::class.java && response.isSuccessful -> response.body?.byteString() as R
+                succeed is GenericArrayType && succeed.genericComponentType === Byte::class.java && response.isSuccessful -> response.body?.bytes() as R
+                succeed === File::class.java && response.isSuccessful -> response.file() as R
                 succeed === Response::class.java -> response as R
-                succeed === File::class.java -> response.file() as R
                 else -> throw ConvertException(response, "An exception occurred while converting the NetConverter.DEFAULT")
             }
         }