angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

storage.upload does not catch error as expected

Open expert26111 opened this issue 8 years ago • 5 comments

Version info

Angular: 5.2.8

Firebase: 4.12

AngularFire: 5.0.0-rc.6

How to reproduce these conditions

https://stackblitz.com/edit/angular-storage-experiment?file=app%2Fapp.component.ts

Steps to set up and reproduce Just try to use the web app and upload a pdf file, the firebase instance have rules that reject such upload, the problem is that in app.component.ts file the try and catch does not work and thrown error is not caught

Sample data and security rules

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if false;
    }
  }
}

Debug output

** Errors in the JavaScript console **

 ERROR Error: Uncaught (in promise): FirebaseStorageError: {"code_":"storage/unauthorized","message_":"Firebase Storage: User does not have permission to access 'java.pdf'.","serverResponse_":"{\n  \"error\": {\n    \"code\": 403,\n    \"message\": \"Permission denied. Could not perform this operation\"\n  }\n}","name_":"FirebaseError"}

** Output from firebase.database().enableLogging(true); **

** Screenshots ** screen_two

Expected behavior

Error to be caught

Actual behavior

Error is not caught

expert26111 avatar Mar 29 '18 12:03 expert26111

try it like this: https://stackblitz.com/edit/angular-storage-experiment-rmcqn4

edit: I just took a closer look at this with my IDE. It seems to make things worse ('then' shouldn't be used that way, and it defeats the purpose of the Percentage observable.)

NELBNL avatar Mar 29 '18 16:03 NELBNL

Hi @NELBNL thank you for your respond, I tried out the stackblitz you send me and uploaded a pdf. I still get an uncaught error for my Post request(403), and would really like to be able to catch that error as well. The picture below shows what I mean and to reproduce the conditions please use the stackblitz you send me. Is that possible? screen_pic

expert26111 avatar Mar 30 '18 10:03 expert26111

@expert26111 The screenshot that you've posted(https://user-images.githubusercontent.com/6114495/38134798-ffd941b2-3414-11e8-8cc8-723d7066c183.png) is not from the stackblitz i posted ( https://stackblitz.com/edit/angular-storage-experiment-rmcqn4 )

It should catch the error. However, I don't think you want to use it in that way...

NELBNL avatar Mar 30 '18 10:03 NELBNL

Hi @NELBNL I am sorry I posted wrong picture, this the actual picture after I used your stackblitz. post_request As you can see here I still have uncaught error for my Post request(403). Please try to reproduce the error using your own stackblitz. Do you think it is possible to prevent it?

expert26111 avatar Mar 30 '18 12:03 expert26111

I've noticed catch is not working as expected in the JS SDK in several spots, can you open an issue on their repo since you're using their API in this case? https://github.com/firebase/firebase-js-sdk/issues/new

jamesdaniels avatar Apr 01 '18 05:04 jamesdaniels