I am using a try-catch in my typescript where I can see the error in the browser console but when I try to convert to string it loses the important part.
the code looks like below:
try{ }catch(err:any){
console.log("error in add asset", err)
const payload = this.core.reportError(err, this.MODULE_NAME + " line#819")
console.log("err payload is::::", payload)
}
reportError(err:any, location: string){
let msg = ""
if(err === undefined || Object.keys(err).length === 0){
msg = ""
}else{
msg = JSON.stringify(err)
}
let email = ''
if(this.userData.profile !== undefined && this.userData.profile.email !== undefined){
email = this.userData.profile.email
}
const payload = {
date: (new Date()).getTime(),
error: msg,
uid: this.userData.profile.uid,
location: location,
email: email
}
return payload
}
What it prints in the console is:
[Log] error in add asset – FirebaseError: [code=invalid-argument]: Function setDoc() called with invalid data. Unsupported field value: undefined (found in field finance.assets.Saving.`1719576795123`.`Tax Free Growth` in document users/KshJnfF9hbgs7jWWwXwXuHRxDWY2)
[Log] err payload is::::
Object
date: 1719576795138
email: "xyz"
error: "{"code":"invalid-argument","name":"FirebaseError"}"
location: "add-asset.component.ts line#810"
uid: "KshJnfF9hbgs7jWWwXwXuHRxDWY2"
So, the err payload eats up the real detailed error in doing JSON.stringify and I am confused why