hegaojian / JetpackMvvm

:chicken::basketball:一个Jetpack结合MVVM的快速开发框架,基于MVVM模式集成谷歌官方推荐的JetPack组件库:LiveData、ViewModel、Lifecycle、Navigation组件 使用Kotlin语言,添加大量拓展函数,简化代码 加入Retrofit网络请求,协程,帮你简化各种操作,让你快速开发项目
https://github.com/hegaojian/JetpackMvvm
Apache License 2.0
3.13k stars 610 forks source link

AppException把传进来的Throwable屏蔽了,希望能开放 #73

Closed nullobject0x01 closed 3 years ago

nullobject0x01 commented 3 years ago

如题,在请求restful api时可能会返回4xx状态码响应,这时抛出的HttpException被AppException屏蔽了,上层获取不到响应状态码,希望能改一下,将传进AppException的exception通过构造函数设置到父类:

class AppException : Exception {

    var errorMsg: String //错误消息
    var errCode: Int = 0 //错误码
    var errorLog: String? //错误日志

    constructor(errCode: Int, error: String?, errorLog: String? = "") : super(error) {
        this.errorMsg = error ?: "请求失败,请稍后再试"
        this.errCode = errCode
        this.errorLog = errorLog?:this.errorMsg
    }
// 将throwable传递出去
    constructor(error: Error,e: Throwable?): super(e) {
        errCode = error.getKey()
        errorMsg = error.getValue()
        errorLog = e?.message
    }
}
hegaojian commented 3 years ago

已更新版本 1.2.4 ,新增AppException添加Throwable字段,如果不是从1.2.3版本升级的话且用到了navigation,请在主Activity中,使用新的 fragment -》name值

<fragment
            android:id="@+id/host_fragment"
            android:name="me.hgj.jetpackmvvm.navigation.NavHostFragmentHideShow"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:navGraph="@navigation/main_navation" />