On my lightning component I have function that calls to server side function to create a case
Controller.apxc
public class CommunityCaseFormController {
@AuraEnabled
public static Id createCase(Case c) {
try {
insert c;
} catch (Exception e) {
String message = e.getMessage();
AuraHandledException auraError = new AuraHandledException(message);
auraError.setMessage(message);
throw auraError;
}
return c.Id;
}
}
I'm getting an error message because an admin created a validation rule for cases on creation. The response.getError()[0].message
from calling the server function has the error message that is in the validation rule, but is has bunch of extra stuff that the user doesn't need to see, such as.
Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,
.: [Priority]
I could use JavaScript to manipulate the string, but in my opinion that shouldn't be required. How do I get my server-side function to return a cleaner error message?