Catch CustomAdapter exception in component

I would like to display error messages generated from a custom adapter (api) to the user in a dialog. 
To achieve this I need to catch the error in the component where the scheduler was added.
How can I receive error messages from a CustomAdapter?
The OnActionFailure schedule event only returns an emtpy source object.

Component

<SfSchedule TValue="AppointmentData" Width="100%" Height="100%">
  <!--<ScheduleEvents TValue="AppointmentData" OnActionFailure="@((args) => { ActionFailure(args); })"></ScheduleEvents>-->
  <ScheduleEvents TValue="Exception" OnActionFailure="@((args) => { ActionFailureExceptionHandler(args); })"></ScheduleEvents>
  <ScheduleEventSettings TValue="AppointmentData">
    <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
  </ScheduleEventSettings>
</SfSchedule>     

public void ActionFailure(Syncfusion.Blazor.Schedule.ActionEventArgs<AppointmentData> args)
{
  //Shows empty object appointmentdata (No info about exception)
  Console.Error.WriteLine(args);
} 

public void ActionFailureHandler(Syncfusion.Blazor.Schedule.ActionEventArgs<Exception> args)
{
  //Shows empty object appointmentdata (Get my exception)
  Console.Error.WriteLine(args);
}

Custom Adapter
public class CustomAdaptor : DataAdaptor
{       
    public async override Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)
      {

                 await Task.Delay(100);

        throw new Exception("Throw my Exception");


return null;
     }
}


6 Replies 1 reply marked as answer

AK Alagumeena Kalaiselvan Syncfusion Team July 7, 2020 03:06 PM UTC

Hi Kevin, 

Thanks for contacting Syncfusion support. 

We have validated your reported case “OnActionFailure event only returns empty source object” and we could replicated this issue at our end. So, we consider this case as defect and logged the defect report for that which can be tracked from the below link. 

We will include the fix in our patch release which is available on 3rd Week of July, 2020. 

Until then we suggest you to use try-catch block inside custom adaptor to handle the error in the component. We have modified your shared sample code based on your requirement and refer the below code for that. 
<div>@Error</div> 
<SfSchedule TValue="AppointmentData" Width="100%" Height="100%"> 
    <ScheduleEvents TValue="AppointmentData" OnActionFailure="@((args) => { ActionFailure(args); })"></ScheduleEvents> 
    @*<ScheduleEvents TValue="Exception" OnActionFailure="@((args) => { ActionFailureExceptionHandler(args); })"></ScheduleEvents>*@ 
    <ScheduleEventSettings TValue="AppointmentData"> 
        <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> 
    </ScheduleEventSettings> 
</SfSchedule> 
 
@code{ 
    public static string Error { get; set; } = "No Errors"; 
    public void ActionFailure(Syncfusion.Blazor.Schedule.ActionEventArgs<AppointmentData> args) 
    { 
        //Shows empty object appointmentdata (No info about exception) 
        Console.Error.WriteLine(args); 
    } 
    public class AppointmentData 
    { 
        public int Id { get; set; } 
        public string Subject { get; set; } 
        public string Location { get; set; } 
        public DateTime StartTime { get; set; } 
        public DateTime EndTime { get; set; } 
        public string Description { get; set; } 
        public bool IsAllDay { get; set; } 
        public string RecurrenceRule { get; set; } 
        public string RecurrenceException { get; set; } 
        public Nullable<int> RecurrenceID { get; set; } 
    } 
    public void ActionFailureHandler(Syncfusion.Blazor.Schedule.ActionEventArgs<Exception> args) 
    { 
        //Shows empty object appointmentdata (Get my exception) 
        Console.Error.WriteLine(args); 
    } 
    public class CustomAdaptor : DataAdaptor 
    { 
        public async override Task<object> 
            ReadAsync(DataManagerRequest dataManagerRequest, string key = null) 
        { 
            try 
            { 
                await Task.Delay(100); 
                throw new Exception("Throw my Exception"); 
            } 
            catch(Exception e) 
            { 
                Error = e.Message;     // To show error message 
                StateHasChanged(); 
            } 
            return null; 
        } 
    } 
} 

Please try with shared way and get back to us, if you need further assistance. 

Regards 
Alagumeena.K 



VM Vengatesh Maniraj Syncfusion Team replied to Alagumeena Kalaiselvan July 15, 2020 11:32 AM UTC

Hi Kevin, 

Thanks for contacting Syncfusion support. 

We have validated your reported case “OnActionFailure event only returns empty source object” and we could replicated this issue at our end. So, we consider this case as defect and logged the defect report for that which can be tracked from the below link. 

We will include the fix in our patch release which is available on 3rd Week of July, 2020. 

Until then we suggest you to use try-catch block inside custom adaptor to handle the error in the component. We have modified your shared sample code based on your requirement and refer the below code for that. 
<div>@Error</div> 
<SfSchedule TValue="AppointmentData" Width="100%" Height="100%"> 
    <ScheduleEvents TValue="AppointmentData" OnActionFailure="@((args) => { ActionFailure(args); })"></ScheduleEvents> 
    @*<ScheduleEvents TValue="Exception" OnActionFailure="@((args) => { ActionFailureExceptionHandler(args); })"></ScheduleEvents>*@ 
    <ScheduleEventSettings TValue="AppointmentData"> 
        <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> 
    </ScheduleEventSettings> 
</SfSchedule> 
 
@code{ 
    public static string Error { get; set; } = "No Errors"; 
    public void ActionFailure(Syncfusion.Blazor.Schedule.ActionEventArgs<AppointmentData> args) 
    { 
        //Shows empty object appointmentdata (No info about exception) 
        Console.Error.WriteLine(args); 
    } 
    public class AppointmentData 
    { 
        public int Id { get; set; } 
        public string Subject { get; set; } 
        public string Location { get; set; } 
        public DateTime StartTime { get; set; } 
        public DateTime EndTime { get; set; } 
        public string Description { get; set; } 
        public bool IsAllDay { get; set; } 
        public string RecurrenceRule { get; set; } 
        public string RecurrenceException { get; set; } 
        public Nullable<int> RecurrenceID { get; set; } 
    } 
    public void ActionFailureHandler(Syncfusion.Blazor.Schedule.ActionEventArgs<Exception> args) 
    { 
        //Shows empty object appointmentdata (Get my exception) 
        Console.Error.WriteLine(args); 
    } 
    public class CustomAdaptor : DataAdaptor 
    { 
        public async override Task<object> 
            ReadAsync(DataManagerRequest dataManagerRequest, string key = null) 
        { 
            try 
            { 
                await Task.Delay(100); 
                throw new Exception("Throw my Exception"); 
            } 
            catch(Exception e) 
            { 
                Error = e.Message;     // To show error message 
                StateHasChanged(); 
            } 
            return null; 
        } 
    } 
} 

Please try with shared way and get back to us, if you need further assistance. 

Regards 
Alagumeena.K 


Hi Kevin,

 

We are glad to announce that our latest weekly release in the version 18.2.0.45 has been rolled out successfully. In that release, we have fixed the reported issue.  So, we suggest you upgrade our Syncfusion packages to avail of the fix in your end.

 

Please find the links below.

 

NuGet Link: https://www.nuget.org/packages/Syncfusion.Blazor/18.2.0.45

Release notes: https://blazor.syncfusion.com/documentation/release-notes/18.2.45/#scheduler

Feedback: https://www.syncfusion.com/feedback/15826/getting-empty-args-value-for-onactionfailure-event-of-scheduler

 

Kindly get back to us if you need any further assistance.

 

Regards,

Vengatesh 



KE Kevin July 15, 2020 01:53 PM UTC

Hi Kalaiselvan,

Could you provide me a sample project how to catch an exception from the CustomDataAdapter?
When I throw an exception in the Custom Data Adapter it ends up in the browser console.

     Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path 'error', line 1, position 10.

I would like to catch the error from the adapter in the code behind of the page where the component is included.

     <ScheduleEvents TValue="Exception" OnActionFailure="@((args) => { ActionFailureExceptionHandler(args); })"></ScheduleEvents>




AK Alagumeena Kalaiselvan Syncfusion Team July 16, 2020 01:00 PM UTC

Hi Kevin, 

Sorry for the inconvenience. 

Unfortunately the fix for issue “OnActionFailure event only returns empty source object” is could not be included in the package version 18.2.0.45. so, we have reopened the respective feedback for tracking the issue status and we will include the fix in our upcoming release which is Scheduled on 3rd week of July, 2020

We would appreciate your patience until then. 

Regards 
Alagumeena.K 



KE Kevin July 27, 2020 02:28 PM UTC


Is there an update for this issue?


VM Vengatesh Maniraj Syncfusion Team July 28, 2020 12:36 PM UTC

Hi Kevin, 

Sorry for the delay. 

We are glad to inform you that the reported issue “Getting empty arguments in actionFailure” has been fixed and rolled out the changes. So kindly upgrade the package version to v18.2.46 to avail of this fix. 

Regards, 
Vengatesh  


Marked as answer
Loader.
Up arrow icon