fix(android-gateway): avoid token clear on transient connect failure

This commit is contained in:
Ayaan Zaidi
2026-02-24 22:11:04 +05:30
committed by Ayaan Zaidi
parent e11e329238
commit 8b24830e07

View File

@@ -307,16 +307,18 @@ class GatewaySession(
val msg = res.error?.message ?: "connect failed"
val hasStoredToken = !storedToken.isNullOrBlank()
val canRetryWithShared = hasStoredToken && trimmedToken.isNotBlank()
if (hasStoredToken) {
deviceAuthStore.clearToken(identity.deviceId, options.role)
}
if (canRetryWithShared) {
val sharedPayload = buildConnectParams(identity, connectNonce, trimmedToken, password?.trim())
res = request("connect", sharedPayload, timeoutMs = 8_000)
}
if (!res.ok) {
val retryMsg = res.error?.message ?: msg
throw IllegalStateException(retryMsg)
val sharedRes = request("connect", sharedPayload, timeoutMs = 8_000)
if (!sharedRes.ok) {
val retryMsg = sharedRes.error?.message ?: msg
throw IllegalStateException(retryMsg)
}
// Stored device token was bypassed successfully; clear stale token for future connects.
deviceAuthStore.clearToken(identity.deviceId, options.role)
res = sharedRes
} else {
throw IllegalStateException(msg)
}
}
handleConnectSuccess(res, identity.deviceId)