From Apex class:
From client-side controller:
@AuraEnabled
public static List<Account> fetchAccount() {
throw new AuraHandledException('User-defined error');
}
From client-side controller:
doInit: function(component, event, helper) {
var action = component.get('c.fetchAccount');
action.setParams({ firstName : cmp.get("v.firstName") });
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set('v.Accounts', response.getReturnValue());
}
else if (component.isValid() && state === "ERROR") {
console.log("Error Message: ", response.getError()[0].message);
}
});
$A.enqueueAction(action);
}
I have caught exception in my @AuraEnabled apex class by AuraHandledException.
ReplyDeleteNow two thing,
1. When my apex class throws error I get error response in aura in particular structure.
2. If exception cause by any trigger which do not handle AuraHandledException then in my component in error response data structure is different compare to point 1.
Any idea ?