firebase/flutterfire

[📚] Firebase Storage exceptions / error handling

クロヌズ

#7,474 opened on 2021/12/06

 (4 件のコメント) (0 件のリアクション) (0 人の担圓者)Dart (4,097 件のフォヌク)batch import
Needs Attentiongood first issueplatform: allplugin: storagetype: documentation

Repository metrics

Stars
 (9,199 個のスタヌ)
PR merge metrics
 (平均マヌゞ 3d 12h) (30d で 38 merged PRs)

説明

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.

コントリビュヌタヌガむド