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

Commit dbf8df12 authored by dev-12's avatar dev-12
Browse files

refactor: denest and make it compatible with upstream

PlayResponse is data class with immutable variable, our fork make it mutable which is not good and un-necessary anyway.
parent 127d30fc
Loading
Loading
Loading
Loading
+33 −31
Original line number Diff line number Diff line
@@ -196,10 +196,11 @@ class GPlayHttpClient @Inject constructor(
    }

    private fun buildPlayResponse(response: Response): PlayResponse {
        return PlayResponse().apply {
            isSuccessful = response.isSuccessful
            code = response.code
        val url = response.request.url
        val code = response.code
        val isSuccessful = response.isSuccessful
        val errorMessage = if (!isSuccessful) response.message else null
        val responseBytes = response.body?.bytes() ?: byteArrayOf()

        when (code) {
            STATUS_CODE_UNAUTHORIZED -> MainScope().launch {
@@ -227,14 +228,15 @@ class GPlayHttpClient @Inject constructor(
            throw GplayHttpRequestException(code, response.message)
        }

            if (response.body != null) {
                responseBytes = response.body!!.bytes()
            }

            if (!isSuccessful) {
                errorString = response.message
        fun PlayResponse.withErrorString(error: String?): PlayResponse {
            return if (error == null) return this else copy(errorString = error)
        }

        return PlayResponse(
            isSuccessful = isSuccessful,
            code = code,
            responseBytes = responseBytes,
        ).withErrorString(errorMessage).apply {
            _responseCode.value = response.code
        }
    }