Exception handling in Lightning is a pain. Instead of Lightning showing regular exceptions one has to catch them in code and rethrow them as AuraHandledExceptions
as shown below:
try {
....
update records;
}
catch(DmlException ex) {
throw new AuraHandledException(ex.getMessage());
}
Especially in cases of DmlExceptions
that can contain multiple errors (one per record) the output is more than ugly:
My questions:
- How can I just show the message of the original first error (the blurry part in my screenshot without all the techie stuff in front of it?
- How can I train AuraHandledException to show a nice title not ApexActionError?
- Is there any technical reason for requiring to rethrow exceptions for Lightning? And is there a roadmap to make this more convenient.
title
parameter and we can set it.