Commit 134ccd49 authored by shiyl's avatar shiyl

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

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