[PM-28990] Skipping vault migration on Network or Timeout error (#6393)

This commit is contained in:
aj-rosado
2026-01-23 16:06:17 +00:00
committed by GitHub
parent 0395d489c2
commit 9f1fad8be0
11 changed files with 323 additions and 38 deletions

View File

@@ -1,6 +1,7 @@
package com.bitwarden.network.util
import okio.ByteString.Companion.decodeBase64
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import java.nio.charset.Charset
import java.security.cert.CertPathValidatorException
@@ -44,6 +45,14 @@ fun Throwable?.isNoConnectionError(): Boolean {
this?.cause?.isNoConnectionError() ?: false
}
/**
* Returns true if the throwable represents a timeout error.
*/
fun Throwable?.isTimeoutError(): Boolean {
return this is SocketTimeoutException ||
this?.cause?.isTimeoutError() ?: false
}
/**
* Returns true if the throwable represents a SSL handshake error.
*/

View File

@@ -3,6 +3,7 @@ package com.bitwarden.network.util
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertNull
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import java.security.cert.CertPathValidatorException
import javax.net.ssl.SSLHandshakeException
@@ -60,6 +61,31 @@ class NetworkUtilsTest {
)
}
@Test
fun `isTimeoutError should return return true for SocketTimeoutException`() {
assertEquals(
true,
SocketTimeoutException().isTimeoutError(),
)
}
@Test
fun `isTimeoutError should return return false for not SocketTimeoutException`() {
assertEquals(
false,
IllegalStateException().isTimeoutError(),
)
}
@Suppress("MaxLineLength")
@Test
fun `isTimeoutError should return return true if exceptions cause is SocketTimeoutException`() {
assertEquals(
true,
Exception(SocketTimeoutException()).isTimeoutError(),
)
}
@Test
fun `isSslHandshakeError should return return true for SSLHandshakeException`() {
assertEquals(