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)
{
throw new Exception("Throw my Exception");
<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;
}
}
} |
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.Feedback Link: https://www.syncfusion.com/feedback/15826/getting-empty-args-value-for-onactionfailure-event-of-scheduler
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 messageStateHasChanged();}return null;}}}
Please try with shared way and get back to us, if you need further assistance.
RegardsAlagumeena.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
Kindly get back to us if you need any further assistance.
Regards,
Vengatesh