Giter Site home page Giter Site logo

Comments (5)

madreain avatar madreain commented on May 1, 2024 2

欢迎使用 https://github.com/madreain/AACHulk,并提出相关问题

from mvvm-architecture.

DaQinShgy avatar DaQinShgy commented on May 1, 2024 1

这是因为协程方式请求没有捕获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 avatar DaQinShgy commented on May 1, 2024 1

这个具体应该怎么改动,上面的代码放在哪里,方便加你联系方式咨询你吗 @DaQinShgy

用项目中的登录举例:
val userInfoResponse = serviceManager.userService.fetchUserOwner()
processApiResponse(userInfoResponse)

processApiResponse方法中虽然有try catch,但如果serviceManager.userService.fetchUserOwner异常,比如timeout,这个时候是无法捕获的,导致app崩溃。改造processApiResponse方法,将函数作为参数传入,就可以避免这个问题,很多时候使用这个项目崩溃就是因为这个原因引起的
processApiResponse{
serviceManager.userService.fetchUserOwner()
}

from mvvm-architecture.

BigBigDeBoy avatar BigBigDeBoy commented on May 1, 2024

这个具体应该怎么改动,上面的代码放在哪里,方便加你联系方式咨询你吗 @DaQinShgy

from mvvm-architecture.

qingmei2 avatar qingmei2 commented on May 1, 2024

@DaQinShgy

谢谢你指出了项目中的问题,正确的方式的确是「将函数作为参数交给processApiResponse」,这样网络请求的行为导致的异常就能够被 processApiResponse 函数中 try catch 捕获到。

很抱歉问题拖了很久,目前最新的代码已经修复,再次感谢。

from mvvm-architecture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.