Skip to content

Commit 7ead0aa

Browse files
committed
fix awaitWhileOnline on throw of DatabaseException
1 parent eb682a4 commit 7ead0aa

File tree

2 files changed

+5
-4
lines changed
  • firebase-database/src
    • commonMain/kotlin/dev/gitlive/firebase/database
    • jsMain/kotlin/dev/gitlive/firebase/database

2 files changed

+5
-4
lines changed

firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ object ServerValue {
8686
val TIMESTAMP = Double.POSITIVE_INFINITY
8787
}
8888

89-
expect class DatabaseException : RuntimeException
89+
expect class DatabaseException(message: String?, cause: Throwable?) : RuntimeException
9090

9191
expect class OnDisconnect {
9292
suspend fun removeValue()

firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ actual class OnDisconnect internal constructor(val js: firebase.database.OnDisco
164164
rethrow { js.set(encode(strategy, value, encodeDefaults)).awaitWhileOnline() }
165165
}
166166

167-
actual class DatabaseException(error: dynamic) :
168-
RuntimeException("${error.code ?: "UNKNOWN"}: ${error.message}", error.unsafeCast<Throwable>())
167+
actual class DatabaseException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
168+
constructor(error: dynamic) : this("${error.code ?: "UNKNOWN"}: ${error.message}", error.unsafeCast<Throwable>())
169+
}
169170

170171
inline fun <T, R> T.rethrow(function: T.() -> R): R = dev.gitlive.firebase.database.rethrow { function() }
171172

@@ -189,7 +190,7 @@ suspend fun <T> Promise<T>.awaitWhileOnline(): T = coroutineScope {
189190

190191
select<T> {
191192
this@awaitWhileOnline.asDeferred().onAwait { it.also { notConnected.cancel() } }
192-
notConnected.onReceive { throw DatabaseException("Database not connected") }
193+
notConnected.onReceive { throw DatabaseException("Database not connected", null) }
193194
}
194195

195196
}

0 commit comments

Comments
 (0)