@@ -21,30 +21,37 @@ class UssdRepository {
21
21
final actualDay = DateTime .now ().day;
22
22
23
23
if (lastDay != actualDay) {
24
- return getUssdCodesRemote ();
24
+ final result = await getUssdCodesRemote ();
25
+
26
+ return result.when (
27
+ success: (data) {
28
+ return Result .success (data: data);
29
+ },
30
+ error: (error) async {
31
+ try {
32
+ final ussdItems = await _localDatasource.getUssdCodes ();
33
+
34
+ return Result .success (data: ussdItems);
35
+ } on UssdCodesCacheException {
36
+ try {
37
+ final ussdItems = await _assetsDatasource.getUssdCodes ();
38
+
39
+ await _localDatasource.saveUssdCodes (ussdItems, '' );
40
+
41
+ return Result .success (data: ussdItems);
42
+ } on Exception {
43
+ return const Result .error (
44
+ message: 'Error al cargar los códigos ussd' ,
45
+ );
46
+ }
47
+ }
48
+ },
49
+ );
25
50
} else {
26
51
final ussdItems = await _localDatasource.getUssdCodes ();
27
52
28
53
return Result .success (data: ussdItems);
29
54
}
30
- } on UssdCodesServerException {
31
- try {
32
- final ussdItems = await _localDatasource.getUssdCodes ();
33
-
34
- return Result .success (data: ussdItems);
35
- } on UssdCodesCacheException {
36
- try {
37
- final ussdItems = await _assetsDatasource.getUssdCodes ();
38
-
39
- await _localDatasource.saveUssdCodes (ussdItems, '' );
40
-
41
- return Result .success (data: ussdItems);
42
- } on Exception {
43
- return const Result .error (
44
- message: 'Error al cargar los códigos ussd' ,
45
- );
46
- }
47
- }
48
55
} on UssdCodesCacheException {
49
56
try {
50
57
final ussdItems = await _assetsDatasource.getUssdCodes ();
0 commit comments