Browse Source

请求结果支持返回null

drake 4 years ago
parent
commit
a5a3fde9ba

+ 2 - 1
kalle/src/main/java/com/yanzhenjie/kalle/simple/Converter.kt

@@ -17,6 +17,7 @@ package com.yanzhenjie.kalle.simple
 
 import com.yanzhenjie.kalle.Request
 import com.yanzhenjie.kalle.Response
+import com.yanzhenjie.kalle.exception.ParseError
 import java.lang.reflect.Type
 
 @Suppress("UNCHECKED_CAST")
@@ -39,7 +40,7 @@ interface Converter {
                     response.log = string
                     return string as S
                 }
-                return null
+                throw ParseError(request, "Only strings are supported by default")
             }
         }
     }

+ 1 - 1
net/src/main/java/com/drake/net/convert/DefaultConvert.kt

@@ -58,7 +58,7 @@ abstract class DefaultConvert(
                 if (jsonObject.getString(this.code) == success) { // 对比后端自定义错误码
                     return if (succeed === String::class.java) body as S else body.parseBody(succeed)
                 } else { // 错误码匹配失败, 开始写入错误异常
-                    throw ResponseException(code, jsonObject.getString(message), request)
+                    throw ResponseException(code, jsonObject.getString(message), request, body)
                 }
             }
             code in 400..499 -> throw RequestParamsException(code, request) // 请求参数错误

+ 1 - 1
sample/src/main/java/com/drake/net/sample/callback/JsonConvert.kt

@@ -20,7 +20,7 @@ import com.drake.net.convert.DefaultConvert
 import com.squareup.moshi.Moshi
 import java.lang.reflect.Type
 
-class JsonConvert : DefaultConvert(code = "code", message = "msg", success = "400") {
+class JsonConvert : DefaultConvert(code = "code", message = "msg", success = "200") {
 
     override fun <S> String.parseBody(succeed: Type): S? {
         return Moshi.Builder().build().adapter<S>(succeed).fromJson(this)