How to catch all different kind of errors from Firebase Storage in Flutter?

Viewed 54

I would like to be able to catch and respond according to specific errors from firebase_storage in my Flutter app.

Here is what i would like to do:

UploadTask task = FirebaseStorage.instance.reference().putFile("filePath");
task.catchError((FirebaseStorageException exception) {
  switch (exception.state) {
    case FirebaseStorageExceptionState.unknown:
       break;
    case FirebaseStorageExceptionState.canceled:
       break;
    ...
  }
})

For now I'm doing the catch this way according to the documentation:

task.catchError((FirebaseException error) {
  if (error.code == "canceled") {
    ...
  }
})

Which is definitely not a good way to go because i don't know all of the String and they may changed in the future...

Is there any way to be able to do this?

0 Answers
Related