Commit 4dfc6b87 by 万齐军

network_api事件上报

parent f1a202ec
......@@ -35,8 +35,6 @@ import okio.BufferedSink
import java.io.EOFException
import java.nio.charset.Charset
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
/**
......@@ -142,8 +140,8 @@ class HttpConfig {
commonParams(),
requestHead(appName),
addEncryptionHeaderParamsInterceptor(),
responseErrorInterceptor()
// respErrorInterceptor()
responseErrorInterceptor(),
respErrorInterceptor(),
)
.setRequestHandler(getRequestHandler())
.setReadTimeout(15)
......@@ -193,22 +191,29 @@ class HttpConfig {
val code = resp.code()
val message = resp.message()
val api = req.url().encodedPath()
if (api.contains("data/bigdata/maidian/writeMaiDianData")) {
return@Interceptor resp
}
if (!resp.isSuccessful) {
Apm.reportEventWithExt("network_api", "resp_fail", api, mapOf("code" to code.toString(), "msg" to message))
Apm.reportEventWithExt("network_api_android", "resp_fail", api, mapOf("code" to code.toString(), "msg" to message))
} else {
try {
val body = resp.body() ?: return@Interceptor resp
val buffer = body.source().buffer()
val source = body.source()
source.request(Long.MAX_VALUE)
val buffer = source.buffer()
if (!isPlaintext(buffer)) return@Interceptor resp
val readString = buffer.clone().readString(Charset.forName("UTF-8"))
val fromJson = Gson().fromJson<BaseAPIResponse<Any>>(readString, BaseAPIResponse::class.java)
if (fromJson == null) {
return@Interceptor resp
}
if (fromJson.code != "200" && fromJson.code != "0") {
Apm.reportEventWithExt("network_api", "business_fail", api, mapOf("code" to code.toString(), "msg" to message))
Apm.reportEventWithExt("network_api_android", "business_fail", api, mapOf("code" to code.toString(), "msg" to message))
}
} catch (throwable: Throwable) {
LogUtil.e(throwable.message)
Apm.reportEventWithExt("network_api_android", "throwable", api, mapOf("msg" to (throwable.message ?: "")))
}
}
return@Interceptor resp
}
......
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