https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

ursus

06/13/2020, 11:20 PM
Copy code
fun <T> body(response: Response<T>): T? {
        return if (!response.isSuccessful) {
            val errorResponse = try {
                val errorBody = response.errorBody()
                if (errorBody != null) {
                    moshi.adapter(ErrorResponse::class.java).fromJson(errorBody.source())
                } else {
                    null
                }
            } catch (ex: Exception) {
                null
            }
            val retryAfterTimestampMillis = errorResponse
                ?.error
                ?.retryAfter
                ?.let(TimestampParserHelper::parseTimestampMillis)

            throw ApiException(
                path = response.raw().request.url.encodedPath,
                errorCode = response.code(),
                errorMessage = errorResponse?.error?.errorMessage,
                retryAfterTimestamp = retryAfterTimestampMillis
            )
        } else {
            response.body()
        }
    }
o

OG

06/14/2020, 2:12 PM
I think okhttp interceptor is a good place to start
2 Views