Просмотр исходного кода

+ JSON异常可以获取字符串信息

drake 5 лет назад
Родитель
Сommit
efa3f4fc83

+ 3 - 2
net/src/main/java/com/drake/net/convert/DefaultConverter.kt

@@ -9,6 +9,7 @@
 
 package com.drake.net.convert
 
+import com.drake.net.error.JsonStructureException
 import com.drake.net.error.ParseJsonException
 import com.drake.net.error.RequestParamsException
 import com.drake.net.error.ServerResponseException
@@ -58,7 +59,7 @@ abstract class DefaultConverter(
                                 succeedData = convert(succeed, body)
                             } catch (e: Exception) {
                                 e.printStackTrace()
-                                throw ParseJsonException()
+                                throw ParseJsonException(body)
                             }
                         }
                     } else {
@@ -67,7 +68,7 @@ abstract class DefaultConverter(
                     }
                 } catch (e: JSONException) {
                     e.printStackTrace()
-                    throw ParseJsonException()
+                    throw JsonStructureException(body)
                 }
             }
             code in 400..499 -> throw RequestParamsException()

+ 2 - 1
net/src/main/java/com/drake/net/error/JsonStructureException.kt

@@ -12,4 +12,5 @@ package com.drake.net.error
  * JSON结构不符
  * 一般情况下属于code和msg无法获取
  */
-class JsonStructureException : Throwable()
+class JsonStructureException(val msg: String) : Throwable() {
+}

+ 1 - 1
net/src/main/java/com/drake/net/error/ParseJsonException.kt

@@ -8,4 +8,4 @@
 package com.drake.net.error
 
 
-class ParseJsonException : Throwable()
+class ParseJsonException(val msg: String) : Throwable()