From 464fb0db73d57b6c4dd0cb9236716f6546270530 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 16 Apr 2025 19:53:53 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/datasource/api/common/response/ResponseExt.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/common/response/ResponseExt.kt b/core/datasource/src/main/java/com/tangem/datasource/api/common/response/ResponseExt.kt index 1699dbc089..926d9213aa 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/common/response/ResponseExt.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/common/response/ResponseExt.kt @@ -23,9 +23,10 @@ internal fun Response.toSafeApiResponse(analyticsErrorHandler: Anal if (code == null) { ApiResponseError.UnknownException(IllegalArgumentException("Unknown error status code: ${code()}")) } else { - sendHttpError(code, analyticsErrorHandler) + val errorBody = errorBody()?.string().orEmpty() // !!!Beware!!! string() closes stream after invocation + sendHttpError(code, analyticsErrorHandler, errorBody) - ApiResponseError.HttpException(code, message(), errorBody()?.string()) + ApiResponseError.HttpException(code, message(), errorBody) } } catch (e: Exception) { Timber.e(e, "UnknownException occured") @@ -39,6 +40,7 @@ internal fun Response.toSafeApiResponse(analyticsErrorHandler: Anal private fun Response.sendHttpError( code: ApiResponseError.HttpException.Code, analyticsErrorHandler: AnalyticsErrorHandler, + errorBody: String, ) { val fullRequestUrl = raw().request.url.toUrl() val shortUrl = fullRequestUrl.authority + fullRequestUrl.path @@ -46,7 +48,7 @@ private fun Response.sendHttpError( ApiErrorEvent( endpoint = shortUrl, code = code.numericCode, - message = errorBody()?.string().orEmpty(), + message = errorBody, ), ) }