Skip to content

Commit 07eea23

Browse files
committed
Add try/catch block for heartbeat sending
1 parent f85abf6 commit 07eea23

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

android/app/src/main/java/com/httpsms/worker/HeartbeatWorker.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ class HeartbeatWorker(appContext: Context, workerParams: WorkerParameters) : Wor
2929
return Result.success()
3030
}
3131

32-
HttpSmsApiService.create(applicationContext).storeHeartbeat(phoneNumbers.toTypedArray(), Settings.isCharging(applicationContext))
33-
Timber.d("finished sending heartbeats to server")
32+
try{
33+
HttpSmsApiService.create(applicationContext).storeHeartbeat(phoneNumbers.toTypedArray(), Settings.isCharging(applicationContext))
34+
Timber.d("finished sending heartbeats to server")
3435

35-
Settings.setHeartbeatTimestampAsync(applicationContext, System.currentTimeMillis())
36-
Timber.d("Set the heartbeat timestamp")
36+
Settings.setHeartbeatTimestampAsync(applicationContext, System.currentTimeMillis())
37+
Timber.d("Set the heartbeat timestamp")
38+
} catch (exception: Exception) {
39+
Timber.e(exception, "Failed to send [${phoneNumbers.joinToString()}] heartbeats to server")
40+
return Result.failure()
41+
}
3742

3843
return Result.success()
3944
}

0 commit comments

Comments
 (0)