Explorar el Código

Fix NetworkMetrics error handling for missing timestamps

- Change retrieveImageDuration from TimeInterval to TimeInterval?
- Return nil instead of 0 when request/response dates are missing
- This prevents masking potential issues with invalid metrics data
onevcat hace 6 meses
padre
commit
c3bf5e8c19
Se han modificado 1 ficheros con 3 adiciones y 3 borrados
  1. 3 3
      Sources/Networking/NetworkMetrics.swift

+ 3 - 3
Sources/Networking/NetworkMetrics.swift

@@ -33,7 +33,7 @@ public struct NetworkMetrics: Sendable {
     public let rawMetrics: URLSessionTaskMetrics
 
     /// The duration of the actual image retrieval (excluding redirects).
-    public let retrieveImageDuration: TimeInterval
+    public let retrieveImageDuration: TimeInterval?
 
     /// The total time from request start to completion (including redirects).
     public let totalRequestDuration: TimeInterval
@@ -135,10 +135,10 @@ public struct NetworkMetrics: Sendable {
     /// Calculates the image retrieval duration for a single transaction 
     /// Formula: responseEndDate - requestStartDate
     /// Represents: Time from sending HTTP request to receiving complete image response
-    private static func calculateRetrieveImageDuration(from transaction: URLSessionTaskTransactionMetrics) -> TimeInterval {
+    private static func calculateRetrieveImageDuration(from transaction: URLSessionTaskTransactionMetrics) -> TimeInterval? {
         guard let start = transaction.requestStartDate,
               let end = transaction.responseEndDate else { 
-            return 0 
+            return nil 
         }
         return end.timeIntervalSince(start)
     }