ursus
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() } }
OG
A modern programming language that makes developers happier.