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,
|
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) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user