AngularFire2 (@angular/fire) How to get error from callable function?
Asked Answered
N

1

6

I'm trying to access a callable function's error message within an Angular environment using the angular fire package. Please see the following code:

Angular (Client-Side)

async myCallableFunction(id: string) {
  try {
    const res = await this.afFunctions.httpsCallable('callableFunction')({
      id
    }).toPromise();

    console.log(res);
  } catch (err) {
    console.error('Error is:', err);
  }
}

Server Side (Firebase Function)

exports.callableFunction = functions.https.onCall((data: {
 id: string
}, context: https.CallableContext) => {
  // throw error for testing only
  throw new https.HttpsError('unknown', 'Test Error Message');
});

And the error message logged to the console is:

[console.error]: "Error is:" { "code": "unknown", "line": 100205, "column": 32, "sourceURL": "http://192.168.1.100:8100/vendor.js" }

How do I access the error message from the response by Cloud Firestore?

Thanks in advance.

Nesmith answered 8/8, 2019 at 19:7 Comment(1)
Did you resolve this?Flatboat
C
0

I have just been stuck with this question in the past hour so I'll post my answer for those wandering here :

console.error('Error is:', err);

is not displaying the whole content of the err object. If you want to access any of the 3 parameters if the err object you will have to access them directly :

  console.error(e.code);
  console.error(e.message);
  console.error(e.details);
Close answered 8/6, 2021 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.