tried to fix timetable and handle kreten api error

This commit is contained in:
Kima
2023-09-18 19:29:55 +02:00
parent dc93985834
commit 98d7468f24
6 changed files with 72 additions and 19 deletions

View File

@@ -89,6 +89,9 @@ class KretaClient {
}
if (res == null) throw "Login error";
if (res.body == 'invalid_grant' || res.body.replaceAll(' ', '') == '') {
throw "Auth error";
}
if (json) {
return jsonDecode(res.body);

View File

@@ -67,15 +67,21 @@ class TimetableProvider with ChangeNotifier {
String iss = user.instituteCode;
List? lessonsJson = await _kreta
.getAPI(KretaAPI.timetable(iss, start: week.start, end: week.end));
if (lessonsJson == null) throw "Cannot fetch Lessons for User ${user.id}";
List<Lesson> lessonsList = lessonsJson.map((e) => Lesson.fromJson(e)).toList();
if (lessons.isEmpty && lessons.isEmpty) return;
if (lessonsJson == null) {
return;
// throw "Cannot fetch Lessons for User ${user.id}";
} else {
List<Lesson> lessonsList =
lessonsJson.map((e) => Lesson.fromJson(e)).toList();
lessons[week] = lessonsList;
if (lessons.isEmpty) return;
await store();
await convertBySettings();
lessons[week] = lessonsList;
await store();
await convertBySettings();
}
}
// Stores Lessons in the database