diff --git a/app/src/main/java/com/infomaniak/mail/data/api/UrlTraceInterceptor.kt b/app/src/main/java/com/infomaniak/mail/data/api/UrlTraceInterceptor.kt index f1e4b37f19..a6a4122d55 100644 --- a/app/src/main/java/com/infomaniak/mail/data/api/UrlTraceInterceptor.kt +++ b/app/src/main/java/com/infomaniak/mail/data/api/UrlTraceInterceptor.kt @@ -28,13 +28,21 @@ class UrlTraceInterceptor : Interceptor { var request = chain.request() val requestContextId = UUID.randomUUID().toString() - SentryDebug.addUrlBreadcrumb(request.url.toString(), requestContextId) request.newBuilder().apply { header("x-infomaniak-request-context-id", requestContextId) request = build() } - return chain.proceed(request) + val response = runCatching { + chain.proceed(request) + }.onFailure { + SentryDebug.addUrlBreadcrumb(request.url.toString(), requestContextId, null) + throw it + }.getOrThrow() + + SentryDebug.addUrlBreadcrumb(request.url.toString(), requestContextId, response.code) + + return response } } diff --git a/app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt b/app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt index 1697f3fb46..b1f0e3ba9b 100644 --- a/app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt +++ b/app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt @@ -61,12 +61,13 @@ object SentryDebug { previousDestinationName = newDestinationName } - fun addUrlBreadcrumb(url: String, requestContextId: String) { + fun addUrlBreadcrumb(url: String, requestContextId: String, responseCode: Int?) { addInfoBreadcrumb( category = "API", data = mapOf( "url" to url, "requestContextId" to requestContextId, + "responseCode" to responseCode.toString(), ), ) }