1

I have the following method which is located within a service, this method in particular saves a user profile nothing to exciting.

// Save user Profile
saveProfile(user: User): Observable<Response> {

    return Observable.fromPromise<Response>(

        this.af.database.object('/users/' + user.userId).update({
            first_name: user.first_name,
            display_name: user.display_name,
            biography: user.biography,
            intent: user.intent,
            seeking: user.seeking,
            training: user.training,
            dayDOB: user.dayDOB,
            monthDOB: user.monthDOB,
            yearDOB: user.yearDOB,
            hobbies: user.hobbies,
            last_name: user.last_name,
            gender: user.gender,
            address: user.Address
        }).then((profile: any) => {
            return new Response('Profile has been saved successfully', true);
        })
            .catch((err: any) => {
                return new Response('Unable to save profile at this time, please try again later.', false);
            }) as Promise<Response>
    )

}

As you can see it returns a Promise of type Reponse this is my custom class which contains a string and a boolean I populate these values based on if the update was a success or not. I then refer the boolean value within my component to decide what to do next.

The issue I am experiencing is when I make this method fail it doesn't return what is specified within the catch section of the method, nor does it console.log any custom text I specify instead it just writes the following:

enter image description here

I have searched the firebase documentation but with no avail, has anyone experienced this before? did you managed to resolve it?

But seriously though why bother having a .catch if you can't catch these exceptions.

1 Answer 1

1

The error you have received is essentially an assertion error; it's not an error that's received from the Firebase database.

You've passed the update method what it considers to be an invalid argument, as the address property is undefined.

Throwing an immediate, synchronous error when an invalid argument is received is a decision that the authors of the Firebase JavaScript client have made and that is unlikely to change. You will have to ensure that you pass it valid input.

Sign up to request clarification or add additional context in comments.

1 Comment

I thought they may of been the case after reading, but I thought I'll the question incase I had missed something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.