try { insert activityList; } catch (DmlException ex) { AuraUtilities.throwAuraHandledException(ex.getTypeName(), ex.getMessage()); }
global with sharing class AuraUtilities {
/*
* @description throwing a custom exception that showing the error messages
*/
public static void throwAuraHandledException(String name, String message) {
throw new AuraHandledException(JSON.serialize(new CustomAuraHandledException(name, message)));
}
/*
* @description A custom exception class extends the exception
*/
public class CustomAuraHandledException extends Exception {
public String name;
public String message;
public CustomAuraHandledException(String name, String message) {
this.name = name;
this.message = message;
}
}
}