You need to sign in to do that
Don't have an account?
Deborah Engelmeyer 4
LWC gets blank message from AuraHandledException
I am using api version 49 and throwing an AuraHandledException in Apex code that is called Imperatively from a LWC.
I have verified the exception message is set using Apex unit tests, but I consistently get a blank message in the error handling section of the LWC code.
Apex Code:
LWC Code:
Am I missing some undocumented trick here? Or is there a bug?
I have verified the exception message is set using Apex unit tests, but I consistently get a blank message in the error handling section of the LWC code.
Apex Code:
Exception ex = new AuraHandledException(''); ex.setMessage('not authorized'); throw ex;
LWC Code:
getData() .then((data) => { console.log(data); // processing for expected result }) .catch((error) => { console.error(error); if (error.body.message === "not authorized") { this.error = noAmgenNewsAuth; } else { // error.body.message is always '' this.error = cannotConnect; } });
Am I missing some undocumented trick here? Or is there a bug?
As mentioned in the above link can you try something like below code:
throw new AuraHandledException('not authorized.');
.catch(error => {
console.error(error);
let error = TOAST_MESSAGE_ERROR;
if (error.body.message == "not authorized") {
error = noAmgenNewsAuth;
} else {
error = cannotConnect;
}
}this.showToast(TOAST_TITLE_ERROR, error, TOAST_VARIANT_ERROR);}
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Looking forward to your response.