fix: modify history repository to handle null response and empty history data
This commit is contained in:
parent
6c265fec33
commit
759f560173
|
|
@ -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/';
|
||||
|
|
|
|||
|
|
@ -18,15 +18,25 @@ class HistoryRepository {
|
|||
page: 1,
|
||||
limit: 10,
|
||||
);
|
||||
if (response.statusCode == 200 && response.data != null) {
|
||||
final List<dynamic> historyData = response.data['payload']['history'];
|
||||
if (historyData.isEmpty) {
|
||||
return []; // Mengembalikan list kosong jika tidak ada data
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final responseData = response.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();
|
||||
} else {
|
||||
throw Exception(
|
||||
'Failed to load learning history: ${response.statusMessage}');
|
||||
return [];
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user