1

I'm using paging3. My RemoteMediator returns Result.Error from catch:

catch (e: Exception) {
            return MediatorResult.Error(handler.getError(e))
        }

Inside fragment I'm listening for state changes:

 adapter.addLoadStateListener { loadState ->
// here some code
}

The problem is that I am not getting LoadState.Error despite what the RemoteMediator returned MediatorResult.Error. Instead of an LoadState.ErrorI get LoadState.NotLoading .I get the rest of the states correctly.

Why might this be happening? Please help me

testivanivan
  • 967
  • 13
  • 36

1 Answers1

1

I might be too late to answer, but since I experienced the same problem I will left my experience for others that might suffer the same case.

When I tried to get error by using code like, if(loadState.refresh is LoadState.Error), I wasn't able to get error. So like the code below, I modified my code.

loadStateListener = { loadState ->
    when {
        loadState.prepend is LoadState.Error -> {
           loadState.prepend as LoadState.Error
        }
        loadState.append is LoadState.Error -> {
            loadState.append as LoadState.Error
        }
        loadState.refresh is LoadState.Error -> {
            loadState.refresh as LoadState.Error
        }
        else -> {
            null
        }
    }

Try checking for all load state type. In my case, when Network exception happens in the middle of scrolling, and loadState type was append and error was also triggered from there.

Hope my answer can be helpful for others.

고수민
  • 33
  • 8