Skip to content

Commit

Permalink
fix: catch error if fail to decode
Browse files Browse the repository at this point in the history
  • Loading branch information
Eywek committed Oct 10, 2022
1 parent 681645d commit 94e2c5e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Sources/ReelevantAnalytics/ReelevantAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,14 @@ public struct ReelevantAnalytics {

// We don't send the event if he is older than 15min
let decoder = JSONDecoder()
let event = try decoder.decode(ReelevantAnalytics.BuiltEvent.self, from: data)
let timeSinceEvent = Int64(Date().timeIntervalSince1970 * 1000) - event.timestamp
if timeSinceEvent <= 15 * 60 * 1000 {
self.send(body: data)
do {
let event = try decoder.decode(ReelevantAnalytics.BuiltEvent.self, from: data)
let timeSinceEvent = Int64(Date().timeIntervalSince1970 * 1000) - event.timestamp
if timeSinceEvent <= 15 * 60 * 1000 {
self.send(body: data)
}
} catch {
os_log("Unable to send queued event from Reelevant analytics SDK: %@", log: OSLog.default, type: .error, error as CVarArg)
}
}
}
Expand Down

0 comments on commit 94e2c5e

Please sign in to comment.