-
-
Save marcossevilla/381be3ee189c791736bfffbcd42281da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeRepository implements ISomeRepository { | |
SomeRepository({ | |
required ILocalDataSource localDataSource, | |
required IRemoteDataSource remoteDataSource, | |
}) : _localDataSource = localDataSource, | |
_remoteDataSource = remoteDataSource; | |
final ILocalDataSource _localDataSource; | |
final IRemoteDataSource _remoteDataSource; | |
@override | |
Future<SomeModel> getModel(int modelId) async { | |
try { | |
final model = await _remoteDataSource.getModel(modelId); | |
await _localDataSource.saveModel(model); | |
return model; | |
} catch (e) { | |
// si el llamado al API falla... | |
try { | |
final model = _localDataSource.getSavedModel(); | |
return model; | |
} catch (e) { | |
throw CacheError(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment