As outlined in this question and accepted answer, in order to make the email send work, you have to specify an alternative address to send from, because the default use, Automated Process, doesn't have a valid email address, so those emails are dropped.
You can, however, send emails via email alert where the From Email Address is NOT "Current User's Email Address" but rather some other organization-wide email or default workflow user.
Since that answer was written, you can now Configure the User and Batch Size for Your Platform Event Trigger with PlatformEventSubscriberConfig. You should be able to set the Platform Event Trigger to a user with a valid address, and the emails should send just fine.
Alternatively, you can do what I've done in my projects. I throw the exception back to the client, as you have, then the client does the separate work of calling back to the server to log the error and do whatever else needs to be done (which, for your case, would be sending an email).
Or, you can choose to not throw an exception. After all, you control the data structures. I've had a project where every method would use some kind of variant of this class:
public class Response {
@AuraEnabled public Boolean success { get; set; }
@AuraEnabled public String response { get; set; }
}
Where success
is set to false if I handle an error, and the response
is whatever I need it to be. It might be a String
, or a Map<String, Object>
, or you could even build some more elaborate design using a custom class, perhaps with subclasses to make it easier to manage.
At any rate, you have at least a few options, though the first should probably work and require the least amount of effort.