I am trying to show the error message from the apex method exception as a toast message while doing imperative call in lwc. I am using ldsUtil.js to simplify the error message. But either way, I am not getting the error message in a toast.
this.error = reduceErrors(error);
console.log('error in save :'+error);
console.log('reduceErrors(error) :'+this.error);
All above 3 lines are printing the error successfully but when I am trying pass reduceErrors(error) or this.error in toast message, the message is coming blank. See screenshot. What am I doing wrong?
.catch(error =>{
this.error = reduceErrors(error);
console.log('error in save :'+error);
console.log('reduceErrors(error) :'+this.error);
const event = new ShowToastEvent({
title: 'Save status',
message: this.error,
//message: reduceErrors(error),
variant: 'error',
});
this.dispatchEvent(event);
});
Imported Modules :
import { LightningElement, wire, api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { reduceErrors } from 'c/ldsUtils';
import saveStatus from '@salesforce/apex/MyClass.saveStatus';
ldsUtils Link: https://github.com/trailheadapps/lwc-recipes/tree/main/force-app/main/default/lwc/ldsUtils