-
Notifications
You must be signed in to change notification settings - Fork 271
Closed
Description
The code below is extracted from GithubRemoteMediator. It did not deal with exceptions. Actually, you need to because everytime if your data retreived from database or network is empty, your app will crash. For example, if I tried to search 'abcsde', the app will crash because the response is empty. (I used the final version of this codelabs doing this search)
LoadType.PREPEND -> {
...
val remoteKeys = getRemoteKeyForFirstItem(state)
?:throw InvalidObjectException("Remote key and the prevKey should not be null")
...
}
LoadType.APPEND -> {
...
if (remoteKeys == null || remoteKeys.nextKey == null) {
throw InvalidObjectException("Remote key should not be null for $loadType")
}
...
}
Most importantly, the crash is very annoying. So we need to dealt with our exceptions. And you could do it like the code below:
LoadType.PREPEND -> {
val remoteKeys = getRemoteKeyForFirstItem(state)
?: return MediatorResult.Error(InvalidObjectException("Remote key and the prevKey should not be null"))// I do not know wehther this is a good description, maybe you could replace it with a new
....
}
LoadType.APPEND -> {
...
if (remoteKeys?.nextKey == null) {
return MediatorResult.Error(InvalidObjectException("Remote key should not be null for $loadType")) // I do not know wehther this is a good description
}
...
}
gurkhaman, prabint, wseme-kiswe, ForceTower, yangjunfei-lotus and 1 moreadam-hurwitz
Metadata
Metadata
Assignees
Labels
No labels