Comments (5)
欢迎使用 https://github.com/madreain/AACHulk,并提出相关问题
from mvvm-architecture.
这是因为协程方式请求没有捕获OkHttp抛出的异常,改造processApiResponse方法,将函数作为参数传入,如下:
suspend fun processResponse(request: suspend () -> Response): Results {
return try {
val response = request()
val responseCode = response.code()
val responseMessage = response.message()
if (response.isSuccessful) {
Results.success(response.body()!!)
} else {
loge { "else:" + responseMessage }
Results.failure(Errors.NetworkError(responseCode, responseMessage))
}
} catch (e: IOException) {
loge { "catch:" + e.toString() }
Results.failure(Errors.NetworkError())
}
}
from mvvm-architecture.
这个具体应该怎么改动,上面的代码放在哪里,方便加你联系方式咨询你吗 @DaQinShgy
用项目中的登录举例:
val userInfoResponse = serviceManager.userService.fetchUserOwner()
processApiResponse(userInfoResponse)
processApiResponse方法中虽然有try catch,但如果serviceManager.userService.fetchUserOwner异常,比如timeout,这个时候是无法捕获的,导致app崩溃。改造processApiResponse方法,将函数作为参数传入,就可以避免这个问题,很多时候使用这个项目崩溃就是因为这个原因引起的
processApiResponse{
serviceManager.userService.fetchUserOwner()
}
from mvvm-architecture.
这个具体应该怎么改动,上面的代码放在哪里,方便加你联系方式咨询你吗 @DaQinShgy
from mvvm-architecture.
谢谢你指出了项目中的问题,正确的方式的确是「将函数作为参数交给processApiResponse」,这样网络请求的行为导致的异常就能够被 processApiResponse
函数中 try catch
捕获到。
很抱歉问题拖了很久,目前最新的代码已经修复,再次感谢。
from mvvm-architecture.
Related Issues (20)
- sharedpref读取问题 HOT 1
- 大佬看下QQ邮件哦
- 网络请求 HOT 1
- 大佬 buildSrc 依赖配置是怎么实现。求赐教 HOT 1
- 首页列表上下滑动时好卡啊 HOT 2
- 登陆退出 HOT 2
- 可以加入开发行列一起丰富这个框架吗 HOT 2
- master分支代码爆红 HOT 2
- 【关于】作者本人对这个MVVM项目的定位是什么? HOT 2
- 登陆 HOT 2
- 登录返回401,Unauthorized HOT 2
- com.google.protobuf plugin找不到的问题 HOT 1
- 关于状态管理的疑问 HOT 4
- ViewModelScope.launch HOT 1
- SSL peer shut down incorrectly HOT 1
- 关于gradle的插件 versionPlugin HOT 3
- 请教一个问题
- 升级viewmodel到2.3.0 升级lifecycle到2.2.0 ,在LoginViewModel中如果构造函数有参数时,就会提示这个错误,不知道怎么改,是代码要修改还是google版本的bug呢
- 大佬我写的列表库和网络请求完美支持MVVM给我个友链如何 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mvvm-architecture.