debug: logging HTTP request/response dans BonsaiApiClient
This commit is contained in:
@@ -4,6 +4,7 @@ import com.planify.mobile.data.bonsai.dto.BonsaiIssueDto
|
|||||||
import com.planify.mobile.data.bonsai.dto.BonsaiMilestoneDto
|
import com.planify.mobile.data.bonsai.dto.BonsaiMilestoneDto
|
||||||
import com.planify.mobile.data.bonsai.dto.BonsaiProjectDto
|
import com.planify.mobile.data.bonsai.dto.BonsaiProjectDto
|
||||||
import com.planify.mobile.data.bonsai.dto.BonsaIssueRequest
|
import com.planify.mobile.data.bonsai.dto.BonsaIssueRequest
|
||||||
|
import android.util.Log
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
@@ -128,13 +129,18 @@ class BonsaiApiClient @Inject constructor(
|
|||||||
.header("Authorization", authHeader)
|
.header("Authorization", authHeader)
|
||||||
.header("Accept", "application/json")
|
.header("Accept", "application/json")
|
||||||
.build()
|
.build()
|
||||||
|
Log.d("BonsaiApi", "$method ${auth.getApiBaseUrl()}/$path body=$jsonBody")
|
||||||
runCatching {
|
runCatching {
|
||||||
httpClient.newCall(request).execute().use { response ->
|
httpClient.newCall(request).execute().use { response ->
|
||||||
val body = response.body?.string() ?: ""
|
val body = response.body?.string() ?: ""
|
||||||
|
Log.d("BonsaiApi", "→ ${response.code} body=$body")
|
||||||
if (!response.isSuccessful) return@withContext ApiResult.Failure("HTTP ${response.code}: $body", response.code)
|
if (!response.isSuccessful) return@withContext ApiResult.Failure("HTTP ${response.code}: $body", response.code)
|
||||||
ApiResult.Success(parse(JSONObject(body)))
|
ApiResult.Success(parse(JSONObject(body)))
|
||||||
}
|
}
|
||||||
}.getOrElse { ApiResult.Failure(it.message ?: "Erreur réseau") }
|
}.getOrElse { e ->
|
||||||
|
Log.e("BonsaiApi", "Erreur réseau", e)
|
||||||
|
ApiResult.Failure(e.message ?: "Erreur réseau")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun BonsaIssueRequest.toJson(): String = JSONObject().apply {
|
private fun BonsaIssueRequest.toJson(): String = JSONObject().apply {
|
||||||
|
|||||||
Reference in New Issue
Block a user