Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d9df776 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

Merge branch '0000-main-3.6.2_gplayapi' into 'main'

fix(auth): map all GooglePlayException subclasses to HTTP status

See merge request !810
parents d5a14e1a 2fcf7b47
Loading
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -24,25 +24,29 @@ fun Throwable.isGplayInternalAppNotFound(): Boolean {
}

fun Throwable.gplayInternalExceptionHttpStatus(): Int? {
    if (this !is GooglePlayException) return null
    return when (this) {
        is GooglePlayException.NotFound -> code.takeIf { it > 0 }
        is GooglePlayException.Server -> code.takeIf { it > 0 }
        else -> null
    }
        is GooglePlayException.AuthException -> code
        is GooglePlayException.AppNotPurchased -> code
        is GooglePlayException.AppRemoved -> code
        is GooglePlayException.AppNotSupported -> code
        is GooglePlayException.EmptyDownloads -> code
        is GooglePlayException.NotFound -> code
        is GooglePlayException.Server -> code
        is GooglePlayException.Unknown -> code
    }.takeIf { it > 0 }
}

fun Throwable.gplayInternalExceptionReason(): String? {
    val resolvedReason = when (this) {
        is GooglePlayException.NotFound -> this.reason
        is GooglePlayException.AppNotPurchased -> this.reason
        is GooglePlayException.AppNotSupported -> this.reason
        is GooglePlayException.AppRemoved -> this.reason
        is GooglePlayException.AuthException -> this.reason
        is GooglePlayException.EmptyDownloads -> this.reason
        is GooglePlayException.Server -> this.reason
        is GooglePlayException.Unknown -> this.reason
        else -> localizedMessage
    }

    return resolvedReason?.takeIf { it.isNotBlank() }
    if (this !is GooglePlayException) return localizedMessage?.takeIf { it.isNotBlank() }
    return when (this) {
        is GooglePlayException.AuthException -> reason
        is GooglePlayException.AppNotPurchased -> reason
        is GooglePlayException.AppRemoved -> reason
        is GooglePlayException.AppNotSupported -> reason
        is GooglePlayException.EmptyDownloads -> reason
        is GooglePlayException.NotFound -> reason
        is GooglePlayException.Server -> reason
        is GooglePlayException.Unknown -> reason
    }.takeIf { it.isNotBlank() }
}