Hello,
We are experiencing an issue with the File Manager component from Syncfusion in a Blazor Server application. When attempting to customize the error message displayed during a failed operation (e.g., read), the component consistently shows the default error message (Status code: 404 and Error Message :
NetworkError: Failed to send on XMLHTTPRequest...) instead of the custom error message defined in the controller.
Technical Details:
OnError event in the File Manager component always displays the default application error message.
Here are some excerpts from the code
In the view :
<FileManagerEvents TValue="FileManagerDirectoryContent" OnError="OnErrorHandler"></FileManagerEvents>
void OnErrorHandler(Syncfusion.Blazor.FileManager.FailureEventArgs args){
//codes ...
}
In controller
case "read":
FileManagerResponse<FileManagerDirectoryContent> response = _fileManager.GetFiles(path, args.ShowHiddenItems, args.Data);
if (response.Error != null)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = Convert.ToInt32(response.Error.Code);
Response.HttpContext.Features.Get<IHttpResponseFeature>().StatusCode = 500;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = response.Error.Message;
return Content("");
}
Hi Radouane,
Greetings from Syncfusion support
We have reviewed your query and understand that you need to display a custom error message and error code in the FileManager component. We suggest using the code below to customize the error message and code. We have modified the path to throw an error.
Refer to the code snippet below for reference.
[PhysicalFileProvider.cs]
|
….
return readResponse; } catch (Exception e) { ErrorDetails er = new ErrorDetails(); er.Message = " your custom message"; er.Code = "500"; if ((er.Code == "401") && !string.IsNullOrEmpty(accessMessage)) { er.Message = accessMessage; } readResponse.Error = er; return readResponse; } }
… |
Sample: attached as zip file.
If we misunderstood your query, please share the provider you are using, along with the code and a video demonstrating the problem. This detail will help us understand your query better and provide the prompt solution you need. If possible, try to replicate the issue in our shared sample.
Best Regards,
Vishwanathan
Hello Vishwanathan ,
Thank you for the suggested solution. Unfortunately, the issue persists. When I implement the code as recommended, the response from the controller does not trigger the OnError handler as expected. Instead, it’s triggering the OnSuccess event, despite containing error information.
What I’m aiming for is that the response with the ErrorDetails object from the controller should be directed to the FileManager OnError event, allowing me to access the custom error message within the FailureEventArgs. This way, I can display the specific message set in the controller.
Could you please advise if there’s any additional configuration required, or if there’s a specific structure the ErrorDetails object needs to have to correctly trigger the OnError event?
Thank you for your assistance.
Best regards,
Hi Radouane,
Upon further validation, we have considered the reported issue “The custom error message and code does not trigger the OnError event of FileManager component” as bug on our end. The fix for this issue will be included in the weekly patch release scheduled for November 19, 2024.
Disclaimer: Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.
We appreciate your patience.
Best Regards,
Vishwanathan
Hi Radouane,
Thanks for your patience.
We are glad to announce that our patch release (V27.2.3) has been rolled out successfully. The “The custom error message and code does not trigger the OnError event of FileManager component” has been resolved in this release.
To access this fix, we suggest you update the package to 27.2.3 and we include the sample in the latest version for your reference.
Sample: attached as zip file.
Feedback link: https://www.syncfusion.com/feedback/62806/the-custom-error-message-and-code-not-trigger-the-onerror-event-of-filemanager
Release Notes: https://blazor.syncfusion.com/documentation/release-notes/27.2.3?type=all#file-manager
Root Cause: The reported issue occurs due to not handling null response data from server previously.
Best regards,
Vishwanathan