[Modify]优化接口错误提示

This commit is contained in:
wushaocheng
2023-01-31 11:17:30 +08:00
parent bf7f9868ea
commit ba5803076e
2 changed files with 3 additions and 11 deletions

View File

@@ -10,13 +10,12 @@ import java.net.UnknownHostException
import java.text.ParseException
/**
* Created by qisan 2022/5/26
* com.qisan.wanandroid.http.exception
* Created by wushaocheng 2023/1/31
*/
class ExceptionHandle {
companion object {
private const val TAG = "ExceptionHandle"
var errorCode = ErrorStatus.UNKNOWN_ERROR
var errorMsg = "請求失敗,請稍後重試"
fun handleException(e: Throwable): String {
@@ -25,25 +24,20 @@ class ExceptionHandle {
is SocketTimeoutException, is ConnectException, is HttpException -> { //均视为网络错误
Log.e(TAG, "網絡連接異常: " + e.message)
errorMsg = "網絡異常,請檢查您的網絡再試~"
errorCode = ErrorStatus.NETWORK_ERROR
}
is JsonParseException, is JSONException, is ParseException -> { //均视为解析错误
Log.e(TAG, "數據解析異常: " + e.message)
errorMsg = "數據解析異常"
errorCode = ErrorStatus.SERVER_ERROR
}
is ApiException -> {//服务器返回的错误信息
errorMsg = e.message.toString()
errorCode = ErrorStatus.SERVER_ERROR
}
is UnknownHostException -> {
Log.e(TAG, "網絡連接異常: " + e.message)
errorMsg = "網絡異常,請檢查您的網絡再試~"
errorCode = ErrorStatus.NETWORK_ERROR
}
is IllegalArgumentException -> {
errorMsg = "參數錯誤"
errorCode = ErrorStatus.SERVER_ERROR
}
else -> {//未知错误
try {
@@ -52,7 +46,6 @@ class ExceptionHandle {
Log.e(TAG, "未知錯誤Debug調試 ")
}
errorMsg = e.message.toString()
errorCode = ErrorStatus.UNKNOWN_ERROR
}
}
return errorMsg