fix(sdk-license): HTTP 错误不回退缓存,防止已吊销设备认证通过
verify 返回 false 后 SDK 会尝试 register,服务端对已吊销设备返回 403。 原 catch 块将 HttpException 与网络错误同等处理,导致 cachedStatus=="ok" 时依然返回 Success。修复:HttpException(4xx/5xx)直接写入 DENIED, 只有真正的网络错误(IOException/超时)才允许离线缓存回退。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
63797ea1cb
当前提交
9fd358deef
@ -15,6 +15,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import retrofit2.HttpException
|
||||||
|
|
||||||
object LicenseSDK {
|
object LicenseSDK {
|
||||||
|
|
||||||
@ -147,10 +148,12 @@ object LicenseSDK {
|
|||||||
persistStatus(STATUS_DENIED)
|
persistStatus(STATUS_DENIED)
|
||||||
return@withContext LicenseResult.Error(result.data?.message ?: "Registration denied")
|
return@withContext LicenseResult.Error(result.data?.message ?: "Registration denied")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Network error: use cached status if available
|
// HTTP errors (4xx/5xx) are explicit server rejections — never fall back to cache.
|
||||||
if (cachedStatus == STATUS_OK) {
|
// Only genuine network errors (IOException, timeout) allow the offline cache path.
|
||||||
|
if (e !is HttpException && cachedStatus == STATUS_OK) {
|
||||||
return@withContext LicenseResult.Success("Offline - using cached status")
|
return@withContext LicenseResult.Success("Offline - using cached status")
|
||||||
}
|
}
|
||||||
|
persistStatus(STATUS_DENIED)
|
||||||
return@withContext LicenseResult.Error(e.message ?: "Network error")
|
return@withContext LicenseResult.Error(e.message ?: "Network error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户