OnActionFailure not fired when there is an exception in OnActionBegin

Hello,
i'm new to Syncfusion (version 19.2.0.57) and Blazor (server-side) too so perhaps i'm not understanding how this is supposed to work... 

Right now i have a Grid and i am Updating and Deleting data on a SQL Server database through the OnActionBegin event.

This is pretty much how my grid looks like (i removed the columns because they use Templates and take a lot of space):

<SfGrid ID="GroupsGrid" @ref="GroupsGrid" DataSource="@groups" AllowPaging="true" AllowFiltering="true" AllowSorting="true">
  <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" ShowDeleteConfirmDialog="true" AllowEditOnDblClick="false"></GridEditSettings>
  <GridEvents OnActionBegin="ActionBeginHandler" OnActionComplete="ActionCompleteHandler" OnActionFailure="ActionFailureHandler" TValue="GroupModel"></GridEvents>
  <GridColumns> .... <GridColumns> </SfGrid>

And this is how the code for the event OnActionBegin looks like:

public async Task ActionBeginHandler(ActionEventArgs<GroupModel> args)
  {
    if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save))
    {
     if (args.Action == "Add")
     {
       await GBLL.AddGroup(args.Data);
     }
     else
     {
       await GBLL.UpdGroup(args.Data);
     }
  }  
  if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete))
  {
    await GBLL.DelGroupByKey(args.Data.GrpId);
  }
}

public async Task ActionFailureHandler(Syncfusion.Blazor.Grids.FailureEventArgs args)
{ // This is never called }



If any of the methods GBLL.AddGroup or GBLL.UpdGroup or GBLL.DelGroupByKey throws an exception ActionFailureHandler is not fired. I'd expect it to fire to show a message to the user, but instead the website crashes giving me the whole exception in the Console of the Browser.
Why? Shouldn't OnActionFailure fire everytime there is an exception during an action?
How am i supposed to catch exceptions and show a popup to the user with the error message?

Thank you.


3 Replies

VN Vignesh Natarajan Syncfusion Team September 2, 2021 05:19 AM UTC

Hi Luca,  
 
Thanks for contacting Syncfusion support.  
 
Query: “ Shouldn't OnActionFailure fire everytime there is an exception during an action? How am i supposed to catch exceptions and show a popup to the user with the error message? 
 
We would like to inform you that OnActionFailure event will be triggered only when there is any failure in Grid actions like ( databinding, Filtering, sorting, searching or CRUD at the source level). This event will not be triggered nor exception will be thrown from OnActionFailure event, when an issue occur while updating the changes in your database.  
 
So we request you to below try catch method to find the exception details and display them in custom popup dialog. Refer the below code example.  
 
public async Task ActionBeginHandler(ActionEventArgs<Order> args) 
{ 
    if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)) 
    { 
        if (args.Action == "Add") 
        { 
            try 
            { 
                await GBLL.AddGroup(args.Data); 
            } 
            catch (Exception Ex) 
            { 
              //catch and display the error message here 
            } 
        } 
        else 
        { 
            try 
            { 
                 await GBLL.UpdGroup(args.Data); 
            } 
            catch (Exception Ex) 
            { 
                //catch and display the error message here 
            } 
  
        } 
    } 
    if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete)) 
    { 
        try 
        { 
             await GBLL.DelGroupByKey(args.Data.GrpId); 
        } 
        catch (Exception Ex) 
        { 
            //catch and display the error message here 
        } 
    } 
} 
 
  
Please get back to us if you have further queries. 
 
Regards, 
Vignesh Natarajan  



LT Luca T September 2, 2021 09:42 AM UTC

Thank you!



VN Vignesh Natarajan Syncfusion Team September 3, 2021 03:20 AM UTC

Hi Luca,  

Thanks for the update.  

We request you to achieve your requirement using the solution provided in previous update. And kindly get back to us if you have further queries. 

Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon