Commit 134ccd49 authored by shiyl's avatar shiyl

数据解析代码块进行异常捕获,防止线上问题

parent f6f0c2b9
...@@ -3,6 +3,9 @@ package com.yidian.bcommon.constant ...@@ -3,6 +3,9 @@ package com.yidian.bcommon.constant
/** /**
* 运行配置,提供切换运行环境的能力(变量配置) * 运行配置,提供切换运行环境的能力(变量配置)
*
* ⚠️⚠️注意:对于使用包名注册的三方SDK,目前不支持使用RunConfig切换,需要使用Flavor进行区分
* 例如:高德地图
*/ */
object RunConfig { object RunConfig {
......
...@@ -54,25 +54,29 @@ class HttpParamsUtils { ...@@ -54,25 +54,29 @@ class HttpParamsUtils {
decodeResult.reason = res.reason decodeResult.reason = res.reason
decodeResult.status = res.status decodeResult.status = res.status
if (rsaResult != null) { if (rsaResult != null) {
if (RunConfig.IS_ENCRYPT) { try {// 捕获数据解析异常, 防止T内部的字端解析失败
val result = BCommonManager.getEncryptIml().rsaDecrypt(rsaResult as String) if (RunConfig.IS_ENCRYPT) {
Timber.tag(BCommonManager.TAG_HTTP).d("response result: $result") val result = BCommonManager.getEncryptIml().rsaDecrypt(rsaResult as String)
val decryptResult = gson.fromJson<HttpDecryptResult<T>>(result, object : TypeToken<HttpDecryptResult<T>>() {}.type) Timber.tag(BCommonManager.TAG_HTTP).d("response result: $result")
val verify = BCommonManager.getEncryptIml().verifySign(decryptResult.reqid + decryptResult.ts, decryptResult.secret) val decryptResult = gson.fromJson<HttpDecryptResult<T>>(result, object : TypeToken<HttpDecryptResult<T>>() {}.type)
return if (verify) { val verify = BCommonManager.getEncryptIml().verifySign(decryptResult.reqid + decryptResult.ts, decryptResult.secret)
Timber.tag(BCommonManager.TAG_HTTP).d("verify success") return if (verify) {
val resultJson = gson.toJson(decryptResult.data) Timber.tag(BCommonManager.TAG_HTTP).d("verify success")
decodeResult.result = gson.fromJson<T>(resultJson, type) val resultJson = gson.toJson(decryptResult.data)
decodeResult decodeResult.result = gson.fromJson<T>(resultJson, type)
decodeResult
} else {
Timber.tag(BCommonManager.TAG_HTTP).d("verify failure")
decodeResult
}
} else { } else {
Timber.tag(BCommonManager.TAG_HTTP).d("verify failure") val resultJson = gson.toJson(rsaResult)
decodeResult Timber.tag(BCommonManager.TAG_HTTP).d("response result: $resultJson")
decodeResult.result = gson.fromJson<T>(resultJson, type)
return decodeResult
} }
} else { } catch (e: Exception) {
val resultJson = gson.toJson(rsaResult) e.printStackTrace()
Timber.tag(BCommonManager.TAG_HTTP).d("response result: $resultJson")
decodeResult.result = gson.fromJson<T>(resultJson, type)
return decodeResult
} }
} }
return decodeResult return decodeResult
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment