Skip to content

FirestoreDataSource - Please add the ability to get an occurred exception #1592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Zeliret opened this issue Mar 1, 2019 · 8 comments
Closed

Comments

@Zeliret
Copy link

Zeliret commented Mar 1, 2019

Right now I can only get an error status and call retry. But I need to get the exact exception to provide an explanation to my users.
I have found the place where the error state is populated and It seems that I need to override a lot of code to get the error message.
Is there a good way to workaround this?

@samtstern
Copy link
Contributor

@Zeliret can you show an example of the code you're using now and maybe some comments on how you'd want it to improve?

@Zeliret
Copy link
Author

Zeliret commented Mar 1, 2019

@samtstern sure. Thanks for the answer.
So, I have a Query instance and configured PagedList builder.
I create a new adapter:

val options = FirestorePagingOptions.Builder<Trip>()
                        .setLifecycleOwner(this)
                        .setQuery(result.data.query, Source.DEFAULT, pagingConfig) {
                            result.data.converter(it)
                        }
                        .build()

                    binding.tripsList.swapAdapter(TripsAdapter(options), false)

Let's assume I get an error while I'm loading a page. I can check it here:

override fun onLoadingStateChanged(state: LoadingState) {
            if( state == LoadingState.ERROR ) {
                retry()
            }
        }

But I can get only the flag. How can I get the actual error? As far as I can see from the source code:

/**
     * Error listener that logs, sets the error state, and sets up retry.
     */
    private abstract class OnLoadFailureListener implements OnFailureListener {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w(TAG, "load:onFailure", e);

            // On error we do NOT post any value to the PagedList, we just tell
            // the developer that we are now in the error state.
            mLoadingState.postValue(LoadingState.ERROR);

            // Set the retry action
            mRetryRunnable = getRetryRunnable();
        }

        protected abstract Runnable getRetryRunnable();
    }

Here the exception just dumped into the log.
So I can not check if it is a network error or show it to the user.

@samtstern
Copy link
Contributor

@Zeliret ah I see that's a good feature request! You're right, there's no good way to get it right now in the Paginated adapters.

@samtstern samtstern added this to the 4.3.2 milestone Mar 1, 2019
@samtstern
Copy link
Contributor

How would you feel about something like a getLastError() call in the paginated adapter classes?

@Zeliret
Copy link
Author

Zeliret commented Mar 1, 2019

How would you feel about something like a getLastError() call in the paginated adapter classes?

That sounds good.
So I could use the flow:

if( state == LoadingState.ERROR ) {
     val ex = getLastError()
     if( ex is IOException )
         retry()
     else
         showErrorMessage(ex)
}

As for me that should works. Thank you! :)

@samtstern
Copy link
Contributor

Yep that's how I imagine it too.

@PatilShreyas
Copy link
Contributor

PatilShreyas commented Mar 30, 2019

We should solve this issue together as same as we implemented in FirebaseRecyclerPagingAdapter.
As we discussed here in PR #1603.

We will override the method as

protected void onError(Exception e) {
}

...and will implement as...

@Override
protected void onError(@NonNull Exception e) {
        mSwipeRefreshLayout.setRefreshing(false);
        Log.e(TAG, e.getMessage(), e);
 }

After this, users will able to get status about caught Exception.
Will it helpful?

@samtstern
Copy link
Contributor

This has been fixed and released in 5.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants