diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ef8c00d2..7fbc93f2a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ ### Enhancements * [Sync] Added option to use managed WebSockets via OkHttp instead of Realm's built-in WebSocket client for Sync traffic (Only Android and JVM targets for now). Managed WebSockets offer improved support for proxies and firewalls that require authentication. This feature is currently opt-in and can be enabled by using `AppConfiguration.usePlatformNetworking()`. Managed WebSockets will become the default in a future version. (PR [#1528](https://github.com/realm/realm-kotlin/pull/1528)). -* `AutoClientResetFailed` exception now reports as the throwable cause any user exceptions that might occur during a client reset. (Issue [#1580](https://github.com/realm/realm-kotlin/issues/1580)) +* [Sync] `AutoClientResetFailed` exception now reports as the throwable cause any user exceptions that might occur during a client reset. (Issue [#1580](https://github.com/realm/realm-kotlin/issues/1580)) +* [Sync] Added a new `SyncSessionAuthExpired` exception subclass that will be sent to the `SyncConfiguration.errorHandler` if the sync session is stopped because the users refresh token is no longer valid and they need to log in again. (Isse [#1640](https://github.com/realm/realm-kotlin/issues/1640)) ### Fixed * Cache notification callback JNI references at startup to ensure that symbols can be resolved in core callbacks. (Issue [#1577](https://github.com/realm/realm-kotlin/issues/1577)) diff --git a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt index 2e6806062d..964cd1cf47 100644 --- a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt +++ b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt @@ -63,6 +63,18 @@ public class WrongSyncTypeException internal constructor(message: String) : Sync public class BadFlexibleSyncQueryException internal constructor(message: String) : SyncException(message) +/** + * Thrown when the sync sessions access token expires and it isn't possible to renew it + * automatically because the users refresh token is no longer valid. + * + * Device Sync is stopped and can only be resumed after closing the realm, logging the user + * back in and reopen the realm by using the new user object. + * + * @see https://www.mongodb.com/docs/atlas/app-services/users/sessions/ + */ +public class AuthExpiredException internal constructor(message: String) : + SyncException(message) + /** * Thrown when the server undoes one or more client writes. Details on undone writes can be found in * [writes]. diff --git a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt index fb72304c78..5568b7ac77 100644 --- a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt +++ b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt @@ -8,6 +8,7 @@ import io.realm.kotlin.internal.interop.sync.AppError import io.realm.kotlin.internal.interop.sync.SyncError import io.realm.kotlin.mongodb.exceptions.AppException import io.realm.kotlin.mongodb.exceptions.AuthException +import io.realm.kotlin.mongodb.exceptions.AuthExpiredException import io.realm.kotlin.mongodb.exceptions.BadFlexibleSyncQueryException import io.realm.kotlin.mongodb.exceptions.BadRequestException import io.realm.kotlin.mongodb.exceptions.CompensatingWriteException @@ -79,6 +80,7 @@ internal fun convertSyncError(syncError: SyncError): SyncException { val errorCode = syncError.errorCode val message = createMessageFromSyncError(errorCode) return when (errorCode.errorCode) { + ErrorCode.RLM_ERR_AUTH_ERROR -> AuthExpiredException(message) ErrorCode.RLM_ERR_WRONG_SYNC_TYPE -> WrongSyncTypeException(message) ErrorCode.RLM_ERR_INVALID_SUBSCRIPTION_QUERY -> {