Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ private void fetchFromNetwork(final LiveData<ResultType> dbSource) {
@Override
public void onResponse(Call<RequestType> call, Response<RequestType> response) {
result.removeSource(dbSource);
saveResultAndReInit(response.body());
if(response.isSuccessful()) {
saveResultAndReInit(response.body());
return;
}
result.addSource(dbSource, newData->{
try {
result.setValue(Resource.error(response.errorBody().string(), newData));
} catch (IOException e) {

// reload from disk whatever we had
result.setValue(Resource.success(newData));
}
});
}

@Override
Expand Down