Flutter/Dart & Firebase Error Messages & Codes - firebase

I am implementing Firebase Auth into my Flutter app. How do I access error codes or user friendly error messages from Firebase? Is this available yet?
For example, on iOS you can get the localisedDescription from an error.
In Dart I have a onError: and catchError Futures which return an error object, but don't appear to have the relevant associated information.

it is available. the problem is that the catchError value is not an object, so you can't loop thru its keys. print/debugPrint just outputs the values without giving you any clue how to reference only one of them.
it has getter methods - code, message, and...details. 'details' is the human-readable result, but it's not documented on the firebase_auth flutter example. do this:
}).catchError((e) {
print(e.details); // code, message, details
});

Related

How to see if a twilio message has been read?

I have a nextjs project and I integrated twilio programmable chat. It basically works. Next step is to add notifications and I have very big problems due to the not updated or lack of doc. I tried this guide for web push notifications but I gave it up because after the step7 I don't know what to do and can't find anything about it.
What I want to do now is to get the status of the messages and eventually update them once I read them. First of all is it possible to do it? I don't find anything about twilio web notifications on the internet.
For example if I want to get the messages of a specific room I do as follows:
const response = await getTwilioClient(token, unique_room_name);
const messages = await response.channel.getMessages(MESSAGES_LIMIT);
messages has the following shape:
{
hasNextPage: boolean,
hasPrevPage: boolean,
items: Message[],
nextPage: () => Message[],
prevPage: () => Message[],
}
And Message looks like this:
So how can I see the status of a message?
Message read status is actually stored on the Member object. A Member is the object that represents a User in a Channel and it has a lastConsumedMessageIndex property which relates to the last message they read.
In order to read the lastConsumedMessageIndex property, you need to set where the member has read up to, using the Channel methods advanceLastConsumedMessageIndex, setAllMessagesConsumed or setNoMessagesConsumed.
I recommend you read the documentation on the Message Consumption Horizon and Read Status.
As an extra note, I see you're asking questions about Twilio Chat, however Twilio Chat will be coming to the end of life in July 2022. We recommend that you migrate to the Twilio Conversations API instead.

Flutter Crashlytics - No Crash log for non-fatal flutter error

We are using firebase_crashlytics: ^0.4.0+1 in a flutter app. Within the runApp() we are starting to listen to errors and crashes just like mentioned in the documentation.
runZonedGuarded(() {
runApp(
..
}, (error, stackTrace) {
FirebaseCrashlytics.instance.recordError(error, stackTrace);
});
In general crashes are reported, but not for these type of crashes EXCEPTION CAUGHT BY WIDGETS LIBRARY.
In some circumstances objects might be null, but instead of getting a crash reported to the firebase crashlytics dashboard, nothing happens. User only receive a grey screen and that is it.
Therefore we only are notified if a user reports these errors, but we receive no logs.
Is this a non-fatal error and we should be using recordFlutterError method?
BTW, this is being called when the error is thrown:
Function originalOnError = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails errorDetails) async {
await FirebaseCrashlytics.instance.recordFlutterError(errorDetails);
// Forward to original handler.
originalOnError(errorDetails);
Even the method originalOnError(errorDetails) is called the error is not recorded in the firebase crashlytics dashboard.
How can we make these non-fatal errors also be reported?
The logging has been done by firebase crashlytics. The default filter in the firebase console dashboard was set to crashes. Removing the filter and we can see all reported errors, crashes, non-fatal errors.
Thanks to this stackoverflow post

List of Firestore Error Codes for Flutter

When using Cloud Firestore in my Flutter application I want to use the error codes to return a localized error message to the user. However, I did not find a list of all the possible error codes that could occur. Is there a list like that or do I have to handle the errors differently?
You can see the list of possible exception codes at the gRPC or at the documentation. But, you need to change the code from uppercase to all lowercase and replace underscore with dash. For example:
PERMISSION_DENIED -> permission-denied
NOT_FOUND -> not-found
And so on.
Also, you need to catch FirebaseException instead of PlatformException in the new version of cloud_firestore.
Please have a look at the exception codes from the firebase firestore documentation.

Where is the documentation for FlutterFire FirebaseException codes?

I'm trying to handle Firebase errors in Flutter using FlutterFire. Various functions throw FirebaseException, for example if calling an HttpsCallable when there is no internet connection. I need to figure out what to do depending on the error - for example, if there is no internet connection, show a message, else if it's an unknown error log an exception.
The exception has a code to achieve this:
/// The optional code to accommodate the message.
///
/// Allows users to identify the exception from a short code-name, for example
/// "no-app" is used when a user attempts to read a [FirebaseApp] which does
/// not exist.
final String code;
But I can't find anywhere where these codes are documented, which kind of makes them useless. I've searched for ages. Am I missing something? Does anyone have a link? How can I achieve this?
Auth error code firebase in code
Core dart code
For user in firebase in code
and so on... Could not find one place where everything is added...

How to properly call FirebaseFirestore.instance.clearPersistence() in Flutter?

I'm facing the same problem as this guy question
But his accepted answer didn't helped me.
The problem:
When an user signs out, and another different user signs in, all data shown on my app is from the previous signed out user due to firebase caching system. I searched about this issue and found a solution that consists in calling this method:
FirebaseFirestore.instance.clearPersistence();
But everytime and everywhere I place this line of code, throws an exception saying I cannot call this method when the client is running:
Exception has occurred.
PlatformException (PlatformException(failed-precondition, Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console., {code: failed-precondition, message: Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console., nativeErrorMessage: Persistence cannot be cleared while the client is running., nativeErrorCode: 9}))
so, how to call this method? or better, is there a best way to solve this problem?
It seems it's necessary to terminate the FirebaseFirestore.instance first.
At the end of my log off method I call:
await FirebaseFirestore.instance.terminate();
await FirebaseFirestore.instance.clearPersistence();
I get no errors thrown and everything seems to be working as it should now.
You should call it immediately after you initialize Firebase, and before you make the first query.
add this to your Login Button 'onPressed':
FirebaseFirestore.instance.terminate();
FirebaseFirestore.instance
.clearPersistence()
.then((value) => signinUser(email, password, context));

Resources