|
@@ -127,28 +127,32 @@ abstract class BaseObserver<T>(private val context: Context) : Observer<T> {
|
|
|
}
|
|
|
|
|
|
override fun onError(e: Throwable) {
|
|
|
- if (e is HttpException) {
|
|
|
- var errorJSon = e.response().errorBody()!!.getJsonString()
|
|
|
- if (errorJSon.contains("html")){
|
|
|
- this.onError(ExceptionHandle.handleException(e))
|
|
|
- return
|
|
|
- }
|
|
|
- val obj = JSONObject(errorJSon)
|
|
|
- if (obj.has("code")){
|
|
|
- val result = ExceptionHandle.ResponeThrowable(e,420)
|
|
|
- result.customMessage = obj.getString("message")
|
|
|
- this.onError(result)
|
|
|
- }else{
|
|
|
- this.onError(ExceptionHandle.handleException(e))
|
|
|
- }
|
|
|
- } else {
|
|
|
- this.onError(ExceptionHandle.ResponeThrowable(e, 1000).then {
|
|
|
- if (e.message == null) {
|
|
|
- it.customMessage = "加载失败!"
|
|
|
+ try {
|
|
|
+ if (e is HttpException) {
|
|
|
+ var errorJSon = e.response().errorBody()!!.getJsonString()
|
|
|
+ if (errorJSon.contains("html")) {
|
|
|
+ this.onError(ExceptionHandle.handleException(e))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ val obj = JSONObject(errorJSon)
|
|
|
+ if (obj.has("code")) {
|
|
|
+ val result = ExceptionHandle.ResponeThrowable(e, 420)
|
|
|
+ result.customMessage = obj.getString("message")
|
|
|
+ this.onError(result)
|
|
|
} else {
|
|
|
- it.customMessage = e.message
|
|
|
+ this.onError(ExceptionHandle.handleException(e))
|
|
|
}
|
|
|
- })
|
|
|
+ } else {
|
|
|
+ this.onError(ExceptionHandle.ResponeThrowable(e, 1000).then {
|
|
|
+ if (e.message == null) {
|
|
|
+ it.customMessage = "加载失败!"
|
|
|
+ } else {
|
|
|
+ it.customMessage = e.message
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (exception: Exception) {
|
|
|
+ this.onError(e)
|
|
|
}
|
|
|
|
|
|
}
|