From 941765a3a353446f87a1eb0619268650321d3c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Wed, 23 Jan 2019 18:28:51 +0100 Subject: [PATCH] Fix empty Maybe in student repository (#224) --- .../github/wulkanowy/data/repositories/StudentRepository.kt | 5 ++++- .../main/java/io/github/wulkanowy/services/job/SyncWorker.kt | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/StudentRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/StudentRepository.kt index 97210da0..a7a6f6ea 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/StudentRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/StudentRepository.kt @@ -7,6 +7,7 @@ import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.repositories.local.StudentLocal import io.github.wulkanowy.data.repositories.remote.StudentRemote import io.reactivex.Completable +import io.reactivex.Maybe import io.reactivex.Single import java.net.UnknownHostException import javax.inject.Inject @@ -41,7 +42,9 @@ class StudentRepository @Inject constructor( } fun getCurrentStudent(decryptPass: Boolean = true): Single { - return local.getCurrentStudent(decryptPass).toSingle() + return local.getCurrentStudent(decryptPass) + .switchIfEmpty(Maybe.error(NoSuchElementException("No current student"))) + .toSingle() } fun saveStudent(student: Student): Single { diff --git a/app/src/main/java/io/github/wulkanowy/services/job/SyncWorker.kt b/app/src/main/java/io/github/wulkanowy/services/job/SyncWorker.kt index c958c22d..6e856671 100644 --- a/app/src/main/java/io/github/wulkanowy/services/job/SyncWorker.kt +++ b/app/src/main/java/io/github/wulkanowy/services/job/SyncWorker.kt @@ -80,6 +80,7 @@ class SyncWorker : SimpleJobService() { val end = LocalDate.now().friday if (start.isHolidays) return RESULT_FAIL_NORETRY + if (!student.isStudentSaved) return RESULT_FAIL_RETRY var error: Throwable? = null