Add logging error from units and symbols during registration (#2507)

This commit is contained in:
Rafał Borcz 2024-03-26 12:54:07 +01:00 committed by GitHub
parent 2e71c50894
commit b7f7b16aef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 6 deletions

View File

@ -195,7 +195,7 @@ ext {
}
dependencies {
implementation 'io.github.wulkanowy:sdk:2.5.3'
implementation 'io.github.wulkanowy:sdk:2.5.4-SNAPSHOT'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'

View File

@ -42,6 +42,7 @@ class StudentRepository @Inject constructor(
): RegisterUser = wulkanowySdkFactory.create()
.getStudentsFromHebe(token, pin, symbol, "")
.mapToPojo(null)
.also { it.logErrors() }
suspend fun getUserSubjectsFromScrapper(
email: String,
@ -52,6 +53,7 @@ class StudentRepository @Inject constructor(
): RegisterUser = wulkanowySdkFactory.create()
.getUserSubjectsFromScrapper(email, password, scrapperBaseUrl, domainSuffix, symbol)
.mapToPojo(password)
.also { it.logErrors() }
suspend fun getStudentsHybrid(
email: String,
@ -61,6 +63,7 @@ class StudentRepository @Inject constructor(
): RegisterUser = wulkanowySdkFactory.create()
.getStudentsHybrid(email, password, scrapperBaseUrl, "", symbol)
.mapToPojo(password)
.also { it.logErrors() }
suspend fun getSavedStudents(decryptPass: Boolean = true): List<StudentWithSemesters> {
return studentDb.loadStudentsWithSemesters().map { (student, semesters) ->
@ -195,10 +198,10 @@ class StudentRepository @Inject constructor(
.authorizePermission(pesel)
suspend fun refreshStudentAfterAuthorize(student: Student, semester: Semester) {
val newCurrentApiStudent = wulkanowySdkFactory
.create(student, semester)
.getCurrentStudent()
?: return Timber.d("Can't find student with id ${student.studentId}")
val wulkanowySdk = wulkanowySdkFactory.create(student, semester)
val newCurrentApiStudent = runCatching { wulkanowySdk.getCurrentStudent() }
.onFailure { Timber.e(it, "Can't find student with id ${student.studentId}") }
.getOrNull() ?: return
val studentName = StudentName(
studentName = "${newCurrentApiStudent.studentName} ${newCurrentApiStudent.studentSurname}"
@ -221,6 +224,18 @@ class StudentRepository @Inject constructor(
appDatabase.clearAllTables()
}
}
private fun RegisterUser.logErrors() {
val symbolsErrors = symbols.filter { it.error != null }
.map { it.error }
val unitsErrors = symbols.flatMap { it.schools }
.filter { it.error != null }
.map { it.error }
(symbolsErrors + unitsErrors).forEach { error ->
Timber.e(error, "Error occurred while fetching students")
}
}
}
class NoAuthorizationException : Exception()

View File

@ -18,7 +18,7 @@ fun Semester.isCurrent(now: LocalDate = now()): Boolean {
}
fun List<Semester>.getCurrentOrLast(): Semester {
if (isEmpty()) throw RuntimeException("Empty semester list")
if (isEmpty()) throw IllegalStateException("Empty semester list")
// when there is only one current semester
singleOrNull { it.isCurrent() }?.let { return it }