The firebase.storage.UploadTask interface has the method on( .., .., error?: ((a: Error) => any) | null, ..).
Checking the error code Error interface doesn't have the code property.
Using the example provided here, in the callback function for error a switch-case statement is used to switch among the error codes. The problem is that code is not recognized as property.
```javascript
...
switch (error.code) {
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
...
````
I suppose the solution is to use FirebaseError instead of Error line 720 of type definition.
https://github.com/firebase/firebase-js-sdk/blob/6b53e0058483c9002d2fe56119f86fc9fb96b56c/packages/storage-types/index.d.ts#L84
Thanks
The problem is also present with Firestore's types:
Waiting for the solution, a workaround could be the explicit casting as follow:
var error = <Firebase.FirebaseError>e;
I guess this will work in the same way with your types @romain-faust
Hope this helps
Ciao
Discussing internally for Firestore, changing Error to FirestoreError sounds like a good idea as long as this doesn't cause a breaking change for anybody (hopefully not, but I'm 100% sure how TypeScript deals with this).
We also need to audit our code to make sure we really do guarantee that it's always a FirestoreError.
Any progress on this?
Fixing this on the Firestore types would be nice as well.
Thank you for bringing this back to our attention. We are re-evaluating the fix and will update this issue once a decision is made.
Doing this for now
(error) => {
const firebaseError = error as firebase.FirebaseError;
// A full list of error codes is available at
// https://firebase.google.com/docs/storage/web/handle-errors
switch (firebaseError.code) {
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
case 'storage/unknown':
// Unknown error occurred, inspect error.serverResponse
break;
}
}
Update: The changes to the Firestore API are being reviewed internally. This API review process is standard for any changes to the public API. If approved, I'll merge #3418. I'm aiming for the first week of August 2020 to have it merged.
Update: Make that the 2nd week of August 2020 :)
The fix for Firestore has been merged: https://github.com/firebase/firebase-js-sdk/pull/3418.
The fix for firebase.storage is still TODO.