Using CRM 2016 Online
I'm trying to catch the InvalidPluginExecutionException in javascript. I've seen older posts on this issue, but nothing more recent.
I have a contact plugin that throws the above exception.
The simplified plugin code is
protected void ExecuteContact(LocalPluginContext localContext)
{
throw new InvalidPluginExecutionException(OperationStatus.Failed, -2136989695,
"My Error Message");
}
In JavaScript, I'm calling Xrm.Page.data.save().then as such
Xrm.Page.data.save().then(
function() {
// handle save success
// Do post save stuff
},
function(e) {
// handle failure
// expect to see e.errorCode and e.message of what was set in the
// InvalidPluginExecutionException
}
);
I'm expecting the error callback to be called and have the e.errorCode and e.message contain the error code and error message, but what I'm seeing is the success callback always gets called.
When I debug the plugin using the profiler (https://community.dynamics.com/crm/b/crminogic/archive/2012/06/11/how-to-debug-plugins-using-profiler), I see the error callback getting called but the e.message contains the profiler debug text (which isn't surprising since we're under the profiler) and stepping through the debugger I know that the InvalidExecutionException is getting thrown.
What would cause the success handler to get called even when there is an InvalidExecutionException from the plugin?
Thanks