Merge branch 'fix-history' into 'master'

fix: modify history repository to handle null response and empty history data

See merge request profile-image/kedaireka/polinema-adapative-learning/mobile-adaptive-learning!24
This commit is contained in:
Naresh Pratista 2024-12-04 15:54:05 +00:00
commit e6a56686ed
2 changed files with 18 additions and 8 deletions

View File

@ -1,3 +1,3 @@
const String baseUrl = 'https://c519-114-6-25-184.ngrok-free.app/'; const String baseUrl = 'https://580d-36-85-62-81.ngrok-free.app/';
const String mediaUrl = 'https://c519-114-6-25-184.ngrok-free.app/api/uploads/'; const String mediaUrl = 'https://580d-36-85-62-81.ngrok-free.app/api/uploads/';

View File

@ -18,15 +18,25 @@ class HistoryRepository {
page: 1, page: 1,
limit: 10, limit: 10,
); );
if (response.statusCode == 200 && response.data != null) {
final List<dynamic> historyData = response.data['payload']['history']; if (response.statusCode == 200) {
if (historyData.isEmpty) { final responseData = response.data;
return []; // Mengembalikan list kosong jika tidak ada data
if (responseData == null ||
responseData['payload'] == null ||
responseData['payload']['history'] == null) {
return [];
} }
final List<dynamic> historyData = responseData['payload']['history'];
if (historyData.isEmpty) {
return [];
}
return historyData.map((json) => HistoryModel.fromJson(json)).toList(); return historyData.map((json) => HistoryModel.fromJson(json)).toList();
} else { } else {
throw Exception( return [];
'Failed to load learning history: ${response.statusMessage}');
} }
} on DioException catch (e) { } on DioException catch (e) {
if (e.response?.statusCode == 404) { if (e.response?.statusCode == 404) {