Skip to content

Commit

Permalink
add details to FirebaseFunctionsException
Browse files Browse the repository at this point in the history
  • Loading branch information
nbransby committed Oct 3, 2023
1 parent f4532f7 commit 26aa3d7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions firebase-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gitlive/firebase-app",
"version": "1.10.1",
"version": "1.10.2",
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
"main": "firebase-app.js",
"scripts": {
Expand All @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
"dependencies": {
"@gitlive/firebase-common": "1.10.1",
"@gitlive/firebase-common": "1.10.2",
"firebase": "9.19.1",
"kotlin": "1.8.20",
"kotlinx-coroutines-core": "1.6.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ suspend fun <T> Task<T>.awaitWhileOnline(): T =
.reference(".info/connected")
.valueEvents
.debounce(2.seconds)
.filter { !it.value<Boolean>() }
.filterNot { it.value<Boolean>() }
.map<DataSnapshot, T> { throw DatabaseException("Database not connected", null) }
)
.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ actual typealias FirebaseFunctionsException = com.google.firebase.functions.Fire

actual val FirebaseFunctionsException.code: FunctionsExceptionCode get() = code

actual val FirebaseFunctionsException.details: Any? get() = details

actual typealias FunctionsExceptionCode = com.google.firebase.functions.FirebaseFunctionsException.Code

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ expect class FirebaseFunctionsException: FirebaseException
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
expect val FirebaseFunctionsException.code: FunctionsExceptionCode

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
expect val FirebaseFunctionsException.details: Any?

expect enum class FunctionsExceptionCode {
OK,
CANCELLED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ actual class HttpsCallableResult constructor(val ios: FIRHTTPSCallableResult) {
decode(strategy, ios.data())
}

actual class FirebaseFunctionsException(message: String, val code: FunctionsExceptionCode) : FirebaseException(message)
actual class FirebaseFunctionsException(message: String, val code: FunctionsExceptionCode, val details: Any?) : FirebaseException(message)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
actual val FirebaseFunctionsException.code: FunctionsExceptionCode get() = code

actual val FirebaseFunctionsException.details: Any? get() = details

actual enum class FunctionsExceptionCode {
OK,
CANCELLED,
Expand Down Expand Up @@ -103,7 +104,7 @@ fun NSError.toException() = when(domain) {
// else -> FunctionsExceptionCode.UNKNOWN
// }
else -> FunctionsExceptionCode.UNKNOWN
}.let { FirebaseFunctionsException(description!!, it) }
}.let { FirebaseFunctionsException(description!!, it, null/*userInfo[FIRFunctionsErrorDetails]*/) }

suspend inline fun <T> T.await(function: T.(callback: (NSError?) -> Unit) -> Unit) {
val job = CompletableDeferred<Unit>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ actual class HttpsCallableResult constructor(val js: JsHttpsCallableResult) {

}

actual class FirebaseFunctionsException(cause: Throwable, val code: FunctionsExceptionCode) : FirebaseException(code.toString(), cause)
actual class FirebaseFunctionsException(cause: Throwable, val code: FunctionsExceptionCode, val details: Any?) : FirebaseException(cause.message, cause)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
actual val FirebaseFunctionsException.code: FunctionsExceptionCode get() = code

actual val FirebaseFunctionsException.details: Any? get() = details

actual enum class FunctionsExceptionCode {
OK,
CANCELLED,
Expand Down Expand Up @@ -96,25 +97,25 @@ fun errorToException(e: dynamic) = (e?.code ?: e?.message ?: "")
.lowercase()
.let {
when {
"cancelled" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.CANCELLED)
"invalid-argument" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.INVALID_ARGUMENT)
"deadline-exceeded" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.DEADLINE_EXCEEDED)
"not-found" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.NOT_FOUND)
"already-exists" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.ALREADY_EXISTS)
"permission-denied" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.PERMISSION_DENIED)
"resource-exhausted" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.RESOURCE_EXHAUSTED)
"failed-precondition" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.FAILED_PRECONDITION)
"aborted" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.ABORTED)
"out-of-range" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.OUT_OF_RANGE)
"unimplemented" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.UNIMPLEMENTED)
"internal" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.INTERNAL)
"unavailable" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.UNAVAILABLE)
"data-loss" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.DATA_LOSS)
"unauthenticated" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.UNAUTHENTICATED)
"unknown" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.UNKNOWN)
"cancelled" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.CANCELLED, e.details)
"invalid-argument" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.INVALID_ARGUMENT, e.details)
"deadline-exceeded" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.DEADLINE_EXCEEDED, e.details)
"not-found" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.NOT_FOUND, e.details)
"already-exists" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.ALREADY_EXISTS, e.details)
"permission-denied" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.PERMISSION_DENIED, e.details)
"resource-exhausted" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.RESOURCE_EXHAUSTED, e.details)
"failed-precondition" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.FAILED_PRECONDITION, e.details)
"aborted" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.ABORTED, e.details)
"out-of-range" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.OUT_OF_RANGE, e.details)
"unimplemented" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.UNIMPLEMENTED, e.details)
"internal" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.INTERNAL, e.details)
"unavailable" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.UNAVAILABLE, e.details)
"data-loss" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.DATA_LOSS, e.details)
"unauthenticated" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.UNAUTHENTICATED, e.details)
"unknown" in it -> FirebaseFunctionsException(e, FunctionsExceptionCode.UNKNOWN, e.details)
else -> {
println("Unknown error code in ${JSON.stringify(e)}")
FirebaseFunctionsException(e, FunctionsExceptionCode.UNKNOWN)
FirebaseFunctionsException(e, FunctionsExceptionCode.UNKNOWN, e.details)
}
}
}
22 changes: 11 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ firebase-perf.skipJsTests=false
firebase-storage.skipJsTests=false

# Versions:
firebase-app.version=1.10.2
firebase-auth.version=1.10.2
firebase-common.version=1.10.2
firebase-config.version=1.10.2
firebase-database.version=1.10.2
firebase-firestore.version=1.10.2
firebase-functions.version=1.10.2
firebase-installations.version=1.10.2
firebase-perf.version=1.10.2
firebase-crashlytics.version=1.10.2
firebase-storage.version=1.10.2
firebase-app.version=1.10.3
firebase-auth.version=1.10.3
firebase-common.version=1.10.3
firebase-config.version=1.10.3
firebase-database.version=1.10.3
firebase-firestore.version=1.10.3
firebase-functions.version=1.10.3
firebase-installations.version=1.10.3
firebase-perf.version=1.10.3
firebase-crashlytics.version=1.10.3
firebase-storage.version=1.10.3

0 comments on commit 26aa3d7

Please sign in to comment.