0
public static void getMember(String id, DataListener<Member> listener){
        FirebaseAgent.getMemberDocumentReference(id).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
            @Override
            public void onSuccess(DocumentSnapshot documentSnapshot) {
                if (documentSnapshot.exists())
                    listener.onDataReady(documentSnapshot.toObject(Member.class));
                else
                    listener.onDataNotFound(MEMBER_NOT_FOUND);
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                // .............. error identification ................
            }
        });
    }

I want to build a helper function with returns that error Firebase throws and I want to store those errors inside an enum

Can someone help with this?

1 Answer 1

0

An operation of reading a document from Firestore might indeed fail, due to many reasons. So assuming that FirebaseAgent.getMemberDocumentReference(id) returns an object of type DocumentReference, to handle the errors, please note that the Exception that might be thrown is of type FirebaseFirestoreException.

I want to build a helper function with returns which error Firebase throws and I want to store those errors inside an enum.

That's a good idea, but please note that there is already an enum present inside the FirebaseFirestoreException class, which is called Code, where you can find all Cloud Firestore status codes. So when such an Exception is thrown you can check the code field against these status codes, and the action according to the use case of your app.

One of the most known Exception that is thrown when you read data from Firestore, is called PERMISSION_DENIED. If you want to read more about that, please check the resource below:

1
  • Hey Mouad. Did my answer help? Can I help you with other information?
    – Alex Mamo
    Commented Mar 26, 2024 at 6:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.