Skip to content

AngularFireStorage.getDownloadUrl() is not handling the error properly #2038

@salah3x

Description

@salah3x

Version info

Angular:
7.2.0
Firebase:
5.8.5
AngularFire:
5.1.1
Other (e.g. Ionic/Cordova, Node, browser, operating system):
node: v10.13.0
chrome: 73.0.3683.86
os: Windows 8.1

How to reproduce these conditions

Steps to set up and reproduce

export class Service{

  constructor(private storage: AngularFireStorage) { }
  getImageUrl(path: string):  Observable<string> {
    return this.storage.ref(path).getDownloadURL().pipe(
      take(1),
      catchError(() => of('/assets/default.png'))
      )
    );
  }
export class Component{
constructor(private service: Service) { }
  url: string;
  getImageUrl(): {
    this.service.getImageUrl(aPathFromSomeModel)
      .subscribe(data => this.url = data, err => console.error(err));
  }

Debug output

** Errors in the JavaScript console **

FirebaseStorageError {code_: "storage/invalid-root-operation", message_: "Firebase Storage: The operation 'getDownloadURL' c…eference using child, such as .child('file.png').", serverResponse_: null, name_: "FirebaseError"}
code: "storage/invalid-root-operation"
code_: "storage/invalid-root-operation"
message: "Firebase Storage: The operation 'getDownloadURL' cannot be performed on a root reference, create a non-root reference using child, such as .child('file.png')."
message_: "Firebase Storage: The operation 'getDownloadURL' cannot be performed on a root reference, create a non-root reference using child, such as .child('file.png')."
name: "FirebaseError"
name_: "FirebaseError"
serverResponse: null
serverResponse_: null
__proto__: Object

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

** Screenshots **
Capture

Expected behavior

When passing an empty, null or undefined path, the error should be handled by the catchError operator.

Actual behavior

The error is not handled by catchError and get passed through the error channel

Fix

I had to do a manual check before calling the getDownloadURL()

  if (!path) {
    return  of('/assets/default.png');
  }

I'm no sure if this is an actual issue or I'm just doing it wrong, so any tip would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions