12

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 !

0

1 Answer 1

1

Catch the error like this and handle it

}, onError: (e) {
        debugPrint('Exception::: ==========>>>>>>> ${e.toString()}');
      });
Sign up to request clarification or add additional context in comments.

1 Comment

This does NOT hide the lines, it just prints a new console debug log with the indicated string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.