0

I have created a reusable LWC JS file

lwcExceptionLogging.js

const lwcException = (err) => {
    console.log(err.name+'--Name');
    var name = err.name;

console.log('log Name--'+name);

}
export {lwcException};

And imported it in one of my LWC JS component

testlwc.js

connectedCallback() {
   
    this.isdesktop=FORM_FACTOR === 'Large'?true:false;
try{
    var j = 1 / abc; 
} 
catch(err){
          
  lwcException(err);
}
}

Am able to call lwcException

But to pass the 'err' from lwcExceptionLogging.js to my apexExceptionClass Apex class value is becoming null.

Any idea how to pass 'err' value to apex method where we are creating Exception__c object in apex class using ES6 modules?

7
  • You passing err to apex or err.name? Jun 7, 2023 at 13:27
  • We need to pass 'err' as we need to insert err.name, err.message and other values to insert Exception__c object in apex
    – Prathyusha
    Jun 7, 2023 at 13:33
  • Can you show your apex also? how are you accepting err in apex method? Jun 7, 2023 at 13:36
  • @auraEnabled public static void saveLWCExceptionLog(err){ Exception__c exc = new Exception__c(); exc.Exception_Message__c = err.name; exc.Exception_Type__c = err.message; exc.IsClientSide__c = true; insert exc; }
    – Prathyusha
    Jun 7, 2023 at 13:41
  • You need to make Wrapper something for error object and then accept that wrapper parameter something like this - @auraEnabled public static void saveLWCExceptionLog(ErrorWrapper err) ... your ErrorWrapper contains name , message, etc Jun 7, 2023 at 14:14

0

You must log in to answer this question.

Browse other questions tagged .