Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firebase Storage - Hide Storage Exception when a file doesn't exist

I'm using Flutter and Firebase Storage for an app. I tried to create a function to know whether a file exists or not:

Future<bool> exists(String path) async {
   bool _exists;
   StorageReference storageReference = FirebaseStorage.instance.ref().child(path);
   try {
      await storageReference.getDownloadURL();
      _exists = true;
   } catch (exception) {
      _exists = false;
   }
   return _exists;
}

It is working but when a file does not exist, it still logs the error:

I/System.out(12012): (HTTPLog)-Static: isSBSettingEnabled false
E/StorageException(12012): StorageException has occurred.
E/StorageException(12012): Object does not exist at location.
E/StorageException(12012):  Code: -13010 HttpResult: 404
E/StorageException(12012): {  "error": {    "code": 404,    "message": "Not Found.  Could not get object",    "status": "GET_OBJECT"  }}
E/StorageException(12012): java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found.  Could not get object",    "status": "GET_OBJECT"  }}
E/StorageException(12012):  at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@17.0.0:455)
E/StorageException(12012):  at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@17.0.0:435)
E/StorageException(12012):  at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@17.0.0:426)
E/StorageException(12012):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:280)
E/StorageException(12012):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@17.0.0:294)
E/StorageException(12012):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:70)
E/StorageException(12012):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@17.0.0:62)
E/StorageException(12012):  at com.google.firebase.storage.GetDownloadUrlTask.run(com.google.firebase:firebase-storage@@17.0.0:74)
E/StorageException(12012):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/StorageException(12012):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/StorageException(12012):  at java.lang.Thread.run(Thread.java:764)

Because of that, the console in now full of those lines and it became very hard to debug anything else...

How can I hide those lines ?

Thank you !

like image 977
Valentin Vignal Avatar asked Mar 17 '26 20:03

Valentin Vignal


1 Answers

Catch the error like this and handle it

}, onError: (e) {
        debugPrint('Exception::: ==========>>>>>>> ${e.toString()}');
      });
like image 142
carrasc0 Avatar answered Mar 20 '26 09:03

carrasc0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!