Browse Source

1.处理拦截器默认返回值为1,处理默认为0导致的请求正常。

0423x6e6f
wangwanlei 4 weeks ago
parent
commit
e30bacf0f8

+ 6
- 2
app/src/main/java/com/xhly/manageapp/viewmodel/BaseViewModel.kt View File

@@ -60,8 +60,12 @@ open class BaseViewModel : CommonBaseViewModel() {
60 60
             } else {
61 61
                 val map = HashMap<String, Any>()
62 62
                 map["password"] = code
63
-                val result = loginService.postExitControl(map)
64
-                pwdResult.value = result.code == 0
63
+                try {
64
+                    val result = loginService.postExitControl(map)
65
+                    pwdResult.value = result.code == 0
66
+                }catch (e:Exception){
67
+                    pwdResult.value =false
68
+                }
65 69
             }
66 70
         }
67 71
     }

+ 2
- 2
corelib/src/main/java/com/xhly/corelib/network/ResponseInterceptor.kt View File

@@ -59,12 +59,12 @@ class ResponseInterceptor : Interceptor {
59 59
     }
60 60
     fun createDefaultResponse(): Response {
61 61
         // 创建默认的响应体内容
62
-        val responseBody = "{\"code\":0,\"msg\":\"\",\"obj\":false}" // 替换为您想要返回的默认响应体内容
62
+        val responseBody = "{\"code\":1,\"msg\":\"\",\"obj\":false}" // 替换为您想要返回的默认响应体内容
63 63
 
64 64
         // 创建默认的响应对象
65 65
         val response = Response.Builder()
66 66
             .code(200) // 替换为您想要的响应码
67
-            .message("{\"code\":0,\"msg\":\"\",\"obj\":false}") // 替换为您想要的响应消息
67
+            .message("{\"code\":1,\"msg\":\"\",\"obj\":false}") // 替换为您想要的响应消息
68 68
             .protocol(okhttp3.Protocol.HTTP_1_1) // 替换为您想要的协议
69 69
             .request(okhttp3.Request.Builder().url("http://example.com").build()) // 替换为请求对象
70 70
             .body(responseBody.toResponseBody()) // 设置响应体

Loading…
Cancel
Save