I'm trying to check if the first request came with the empty object, to display a layout indicating that it has no item.
My solution was to create an exception of my own. I would like to know if there is another better way. Because I looked in the documentation and found nothing.
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Item> {
return try {
val position = params.key ?: FIRST_PAGE_INDEX
val response = api.getItem(position, params.loadSize, searchKey)
val nextKey = response?.next
val itemList = response?.itemList ?: emptyList()
if (itemList.isNotEmpty()) {
LoadResult.Page(
data = itemList,
prevKey = null,
nextKey = if (nextKey == LAST_PAGE_INDEX) null else nextKey
)
} else {
LoadResult.Error(EmptyListException())
}
} catch (exception: IOException) {
LoadResult.Error(exception)
} catch (exception: HttpException) {
LoadResult.Error(exception)
}
}