firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.65k stars 3.96k forks source link

[📚] Firebase Storage exceptions / error handling #7474

Open Tom3652 opened 2 years ago

Tom3652 commented 2 years ago

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 saw only 1 line in the documentation :

Future<void> uploadFile(String filePath) async {
  File file = File(filePath);

  try {
    await firebase_storage.FirebaseStorage.instance
        .ref('uploads/file-to-upload.png')
        .putFile(file);
  } on firebase_core.FirebaseException catch (e) {
    // e.g, e.code == 'canceled'
  }
}

Saying e.code == 'canceled'. Fine, but what are the others String we should catch as code please ?

I think all of the error codes should be added, or an enum describing the error state would also be great if possible.

Ehesp commented 2 years ago

This is related; https://github.com/FirebaseExtended/flutterfire/pull/3402#issuecomment-685402151

We had a lot of back and forth on doing enums - the issue is we wrap the native SDKs and simply pass on the error code, so we're not actually 100% sure on what all of those error codes could be, especially given different platforms have different codes.

I'll revive the chat and see if we can implement something at least.

Tom3652 commented 2 years ago

Thanks for the reply @Ehesp and the link, i understand better now this issue. Anyway it would be awesome if something would come up :)

darshankawar commented 1 year ago

@Tom3652 Can you check if this documentation helps and addresses your issue ?

Tom3652 commented 1 year ago

Yes @darshankawar it answers my needs for the second part of the question, but it's a real work for developers to follow the updates.

It would be much easier for us to deal with enums and let Firebase do internally the mapping when they update the SDKs in my opinion, but would be more work to be done on FlutterFire to test and update the code values when the native SDKs are updated if needed