diff --git a/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ExceptionHandler.kt b/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ExceptionHandler.kt index 501baaf..be37e35 100644 --- a/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ExceptionHandler.kt +++ b/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ExceptionHandler.kt @@ -1,7 +1,6 @@ package com.quyunshuo.androidbaseframemvvm.common.helper import com.quyunshuo.androidbaseframemvvm.base.utils.toast -import com.quyunshuo.androidbaseframemvvm.common.helper.ResponseExceptionEnum as ExceptionType /** * 响应code异常统一处理 @@ -26,10 +25,10 @@ suspend fun responseCodeExceptionHandler( ) { // 进行异常的处理 when (code) { - ExceptionType.INTERNAL_SERVER_ERROR.getCode() -> { - toast(ExceptionType.INTERNAL_SERVER_ERROR.getMessage()) + ResponseCodeEnum.ERROR.getCode() -> { + toast(ResponseCodeEnum.ERROR.getMessage()) throw ResponseEmptyException() } - ExceptionType.SUCCESS.getCode() -> successBlock.invoke() + ResponseCodeEnum.SUCCESS.getCode() -> successBlock.invoke() } } \ No newline at end of file diff --git a/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseExceptionEnum.kt b/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseCodeEnum.kt similarity index 54% rename from lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseExceptionEnum.kt rename to lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseCodeEnum.kt index 3e30d48..a2f562b 100644 --- a/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseExceptionEnum.kt +++ b/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseCodeEnum.kt @@ -1,37 +1,38 @@ package com.quyunshuo.androidbaseframemvvm.common.helper /** - * 请求响应异常枚举的抽象 + * 请求响应code枚举抽象 * * @author Qu Yunshuo * @since 2021/7/9 2:56 下午 */ -interface ResponseExceptionEnumCode { +interface IResponseCode { /** - * 获取该异常枚举的code码 + * 获取该枚举的code码 * @return Int */ fun getCode(): Int /** - * 获取该异常枚举的描述 + * 获取该枚举的描述 * @return String */ fun getMessage(): String } /** - * 请求响应异常的类型 + * 请求响应code的枚举 * * @author Qu Yunshuo * @since 2021/7/9 2:55 下午 */ -enum class ResponseExceptionEnum : ResponseExceptionEnumCode { +enum class ResponseCodeEnum : IResponseCode { - INTERNAL_SERVER_ERROR { - override fun getCode() = 500 - override fun getMessage() = "服务器内部错误" + // 通用异常 + ERROR { + override fun getCode() = 100 + override fun getMessage() = "处理失败" }, // 成功 diff --git a/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseException.kt b/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseException.kt index e3a10ba..9608128 100644 --- a/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseException.kt +++ b/lib_common/src/main/java/com/quyunshuo/androidbaseframemvvm/common/helper/ResponseException.kt @@ -1,18 +1,23 @@ package com.quyunshuo.androidbaseframemvvm.common.helper -import com.quyunshuo.androidbaseframemvvm.common.helper.ResponseExceptionEnum as ExceptionType - +/** + * 自定义响应异常的抽象类型 + * + * @author Qu Yunshuo + * @since 2021/8/27 9:50 上午 + */ +interface IResponseException /** * 请求响应异常,主要为各种code码专门定义的异常 * - * @param type ResponseExceptionEnum 异常类型枚举,用于标记该异常的类型 + * @param type IResponseCode 异常类型枚举,用于标记该异常的类型 * @param msg String 异常信息 * * @author Qu Yunshuo * @since 2021/7/9 2:57 下午 */ -class ResponseException(val type: ExceptionType, val msg: String) : Exception() +class ResponseException(val type: IResponseCode, val msg: String) : Exception(), IResponseException /** * 空异常,表示该异常已经被处理过了,不需要再做额外处理了 @@ -20,4 +25,4 @@ class ResponseException(val type: ExceptionType, val msg: String) : Exception() * @author Qu Yunshuo * @since 2021/7/9 3:11 下午 */ -class ResponseEmptyException : Exception() \ No newline at end of file +class ResponseEmptyException : Exception(), IResponseException \ No newline at end of file