Add SessionRestorationException, make sure ClientException can expose it through the cause property
This commit is contained in:
parent
33441d9d40
commit
10224d8e01
5 changed files with 26 additions and 9 deletions
|
|
@ -20,6 +20,7 @@ import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
|||
import io.element.android.libraries.matrix.api.auth.MatrixHomeServerDetails
|
||||
import io.element.android.libraries.matrix.api.auth.OidcDetails
|
||||
import io.element.android.libraries.matrix.api.auth.OidcPrompt
|
||||
import io.element.android.libraries.matrix.api.auth.SessionRestorationException
|
||||
import io.element.android.libraries.matrix.api.auth.external.ExternalSession
|
||||
import io.element.android.libraries.matrix.api.auth.qrlogin.MatrixQrCodeLoginData
|
||||
import io.element.android.libraries.matrix.api.auth.qrlogin.QrCodeLoginStep
|
||||
|
|
@ -91,10 +92,10 @@ class RustMatrixAuthenticationService(
|
|||
}
|
||||
rustMatrixClientFactory.create(sessionData)
|
||||
} else {
|
||||
error("Token is not valid")
|
||||
throw SessionRestorationException.InvalidToken()
|
||||
}
|
||||
} else {
|
||||
error("No session to restore with id $sessionId")
|
||||
throw SessionRestorationException.MissingSession(sessionId)
|
||||
}
|
||||
}.mapFailure { failure ->
|
||||
failure.mapClientException()
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ fun Throwable.mapRecoveryException(): RecoveryException {
|
|||
}
|
||||
}
|
||||
else -> RecoveryException.Client(
|
||||
ClientException.Other("Unknown error")
|
||||
ClientException.Other("Unknown error", this)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,16 @@ fun Throwable.mapClientException(): ClientException {
|
|||
return when (this) {
|
||||
is RustClientException -> {
|
||||
when (this) {
|
||||
is RustClientException.Generic -> ClientException.Generic(msg, details)
|
||||
is RustClientException.Generic -> ClientException.Generic(message = msg, details = details, cause = this)
|
||||
is RustClientException.MatrixApi -> ClientException.MatrixApi(
|
||||
kind = kind.map(),
|
||||
code = code,
|
||||
message = msg,
|
||||
details = details,
|
||||
cause = this,
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> ClientException.Other(message ?: "Unknown error")
|
||||
else -> ClientException.Other(message ?: "Unknown error", this)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue