Sample Code:
We can use System.AuraHandledException
to return custom error message from server side apex controller to lightning component in Salesforce.
string errorMessage = 'Your Error Message'; AuraHandledException auraEx = new AuraHandledException(errorMessage); auraEx.setMessage(errorMessage); throw auraEx;