-
Notifications
You must be signed in to change notification settings - Fork 4k
[firebase_storage] to handle errors like a security error #792
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
Comments
The issue at flutter/flutter#18547 has been closed and moved here. Future collaboration on this issue will be done here. |
Maybe that wasn't the same issue as I thought. I wasn't able to catch errors when using
Thanks to architecture changes I was able to use async/await properly and I'm now catching issue try {
await storageReference.getDownloadURL();
StorageFileDownloadTask storageFileDownloadTask;
storageFileDownloadTask = storageReference.writeToFile(image);
final int byteNumber =
(await storageFileDownloadTask.future).totalByteCount;
debugPrint('downloaded image size ${byteNumber.toString()}');
} on Exception catch(e) {
return Left(e);
} |
In my case I'd like to display an error message if the file doesn't upload due to security rules restrictions. The debug console outputs the below but I can't catch anything.
The exception is being recognized in the subscription but I'm not sure what to do with that: try {
FirebaseStorage _storage =
await RootProject.getStorage(StorageBucket.users);
StorageUploadTask _uploadTask = _storage.ref().child('path').putFile(
file,
);
final StreamSubscription<StorageTaskEvent> streamSubscription =
_uploadTask.events.listen((event) {
if (event.type == StorageTaskEventType.failure) {
// works but ...
}
});
await _uploadTask.onComplete;
streamSubscription.cancel();
} catch (e) {
// nothing ...
} |
it doesn't catch anything, and it's better to add await before storageReference.getDownloadURL() |
This works for me.
|
I have this issue as well - however much I await and try / catch the executions are still filling up my debug console and it drives me nuts. Any updates on this at all would be very much appreciated ! |
@samarthagarwal doesn't seem to work for me... Environment and package versions all up to date, any further help gratefully received ;-)
|
@mistyn8 You are right. It worked for me but now it does not. I don't remember the version I was using. |
@samarthagarwal cheers for the reply.. so regression issue? |
The issue I am facing is probably related to this.
Produces the aforementioned debug message in the console:
However, the catchErr works well, because the message "Profile pic not found" is written in the console, and the _profileImageUrl variable is set to none. The result is exactly the same with the similar (maybe more correct?) code:
Also here the exception is caught ("Profile pic not found" is printed), but the error in the console is still written. |
I think this is working as intended; you can catch the error but it still logs, these error logs you are seeing are Java stack traces coming from the native Firebase Android SDK - it logs errors by default, the plugin code itself for FlutterFire isn't logging/printing these as far as I can see. Having said that we will be working on improved error handling across the board, e.g. #1456 #1223 |
I want to handle errors like security error
PlatformException(sign_in_failed, FIRStorageErrorDomain, User does not have permission to access
I tried try catch block but no luck.
The text was updated successfully, but these errors were encountered: