mirror of
https://github.com/bitwarden/android.git
synced 2026-03-11 12:44:17 -05:00
[PM-28990] Skipping vault migration on Network or Timeout error (#6393)
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user