Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-16 19:53:53 +05:00
parent c40b743a4f
commit 464fb0db73

View file

@ -23,9 +23,10 @@ internal fun <T : Any> Response<T>.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 <T : Any> Response<T>.toSafeApiResponse(analyticsErrorHandler: Anal
private fun <T : Any> Response<T>.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 <T : Any> Response<T>.sendHttpError(
ApiErrorEvent(
endpoint = shortUrl,
code = code.numericCode,
message = errorBody()?.string().orEmpty(),
message = errorBody,
),
)
}