添加了注释,完善了参数校验及空值处理

This commit is contained in:
zxj
2025-07-09 15:29:52 +08:00
parent de80a26c2c
commit 6cf7b4fb9b
42 changed files with 584 additions and 334 deletions
@@ -1,29 +0,0 @@
package com.sw.inbound.network.interceptor
import com.google.gson.JsonParseException
import com.sw.inbound.model.exception.NetException
import okhttp3.Interceptor
import okhttp3.Response
import retrofit2.HttpException
import timber.log.Timber
import java.io.IOException
class ErrorInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
try {
val response = chain.proceed(chain.request())
if (!response.isSuccessful) {
throw NetException(response.code, "HTTP Error ${response.code}")
}
return response
} catch (e: Exception) {
Timber.e(e)
throw when (e) {
is IOException -> NetException(-1, "Network error: ${e.message}")
is JsonParseException -> NetException(-2, "Data parse error")
is HttpException -> NetException(-3, e.message ?: "未知错误")
else -> NetException(-100, e.message ?: "未知错误")
}
}
}
}
@@ -6,6 +6,9 @@ import com.sw.inbound.utils.SPUtil
import okhttp3.Interceptor
import okhttp3.Response
/**
* 请求拦截器
*/
class RequestInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()