Browse Source

+ JsonStructureException 解析Code和Message错误抛出异常

drake 5 years ago
parent
commit
05e6097838

+ 1 - 1
net/build.gradle

@@ -40,7 +40,7 @@ dependencies {
     api 'com.yanzhenjie:okalle:0.1.7'
 
     compileOnly 'androidx.appcompat:appcompat:1.1.0'
-    compileOnly 'com.github.liangjingkanji:BRV:1.0.6'
+    compileOnly 'com.github.liangjingkanji:BRV:1.0.8'
 
     compileOnly 'io.reactivex.rxjava2:rxkotlin:2.3.0'
     compileOnly 'io.reactivex.rxjava2:rxandroid:2.1.1'

+ 2 - 5
net/src/main/java/com/drake/net/NetConfig.kt

@@ -14,10 +14,7 @@ import android.app.Dialog
 import android.widget.Toast
 import androidx.fragment.app.FragmentActivity
 import com.drake.brv.PageRefreshLayout
-import com.drake.net.error.ParseJsonException
-import com.drake.net.error.RequestParamsException
-import com.drake.net.error.ResponseException
-import com.drake.net.error.ServerResponseException
+import com.drake.net.error.*
 import com.drake.net.observer.DialogObserver
 import com.drake.net.observer.PageObserver
 import com.yanzhenjie.kalle.Kalle
@@ -45,6 +42,7 @@ object NetConfig {
             is ReadException -> app.getString(R.string.read_exception)
             is ParseError -> app.getString(R.string.parse_error)
             is ParseJsonException -> app.getString(R.string.parse_json_error)
+            is JsonStructureException -> app.getString(R.string.json_structure_error)
             is RequestParamsException -> app.getString(R.string.request_error)
             is ServerResponseException -> app.getString(R.string.server_error)
             is ResponseException -> msg
@@ -56,7 +54,6 @@ object NetConfig {
 
         Toast.makeText(app, message, Toast.LENGTH_SHORT).show()
     }
-
 }
 
 

+ 15 - 0
net/src/main/java/com/drake/net/error/JsonStructureException.kt

@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2018, Umbrella CompanyLimited All rights reserved.
+ * Project:Net
+ * Author:Drake
+ * Date:10/30/19 8:15 PM
+ */
+
+package com.drake.net.error
+
+
+/**
+ * JSON结构不符
+ * 一般情况下属于code和msg无法获取
+ */
+class JsonStructureException : Throwable()

+ 2 - 4
net/src/main/java/com/drake/net/observer/PageObserver.kt

@@ -13,10 +13,7 @@ import android.widget.Toast
 import com.drake.brv.PageRefreshLayout
 import com.drake.net.NetConfig
 import com.drake.net.R
-import com.drake.net.error.ParseJsonException
-import com.drake.net.error.RequestParamsException
-import com.drake.net.error.ResponseException
-import com.drake.net.error.ServerResponseException
+import com.drake.net.error.*
 import com.yanzhenjie.kalle.exception.*
 import io.reactivex.observers.DefaultObserver
 
@@ -43,6 +40,7 @@ abstract class PageObserver<M>(val pageRefreshLayout: PageRefreshLayout) : Defau
                 is ReadException -> NetConfig.app.getString(R.string.read_exception)
                 is ParseError -> NetConfig.app.getString(R.string.parse_error)
                 is ParseJsonException -> NetConfig.app.getString(R.string.parse_json_error)
+                is JsonStructureException -> NetConfig.app.getString(R.string.json_structure_error)
                 is RequestParamsException -> NetConfig.app.getString(R.string.request_error)
                 is ServerResponseException -> NetConfig.app.getString(R.string.server_error)
                 is ResponseException -> msg

+ 1 - 0
net/src/main/res/values/strings.xml

@@ -15,6 +15,7 @@
     <string name="parse_error">解析数据时发生异常</string>
     <string name="read_exception">读取数据错误</string>
     <string name="parse_json_error">解析JSON错误</string>
+    <string name="json_structure_error">解析JSON错误</string>
     <string name="request_error">请求参数错误</string>
     <string name="server_error">服务响应错误</string>
     <string name="other_error">服务器未响应</string>

+ 2 - 2
sample/build.gradle

@@ -38,7 +38,7 @@ dependencies {
 
     implementation 'com.squareup.moshi:moshi-kotlin:1.8.0'
     kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.8.0'
-    implementation 'com.github.liangjingkanji:BRV:1.0.6'
+    implementation 'com.github.liangjingkanji:BRV:1.0.8'
     implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
     implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
-}
+}

+ 0 - 1
sample/src/main/java/com/drake/net/sample/MainActivity.kt

@@ -9,6 +9,5 @@ class MainActivity : AppCompatActivity() {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_main)
 
-
     }
 }