JS SDK does not catch error as expected
[REQUIRED] Describe your environment
- Operating System version: Ubuntu 17.10
- Firebase SDK version: 4.12
- Firebase Product: storage
[REQUIRED] Describe the problem
I am trying to use storage as I am uploading pdf files from Angular front end app to. I use try and catch but because there are certain permissions an exception is thrown. Looks like the exception is not caught. I have posted this issue over here: https://github.com/angular/angularfire2/issues/1534 but I have been referred to this library.
Steps to reproduce:
Just try to use the stackblitz 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
https://stackblitz.com/edit/angular-storage-experiment-rmcqn4
####Exception:
POST https://firebasestorage.googleapis.com/v0/b/eddystone-dev-e4351.appspot.com/o?name=onGoingCoursesLeft.pdf 403 ()
Sample data and security rules
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if false;
}
}
}
Picture

The upload is an asynchronous operation, so you won't be able to catch the error with a try-catch block. The storage.upload method returns a Promise - in your code sample it looks like you are already using the .catch method to handle the error by printing to the console (the line starting with "errr").
If you're not familiar with Promises, there are a lot of online resources explaining how they work. This article might be a helpful read.
In addition, most browsers will log a red line like the one in your example to the console regardless of whether the code that sent the rejected request did something reasonable with the error - there isn't a way to disable this in Chrome as far as I know, and I imagine Opera works similarly. The presence of a red request log in the console doesn't generally indicate a bug.
In summary, this is working as intended.