Unable to Customize Status Code and Error Message in File Manager Component - Blazor Server

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:

  • Environment: Blazor Server application
  • Syncfusion Component: File Manager
  • Issue: Despite setting a custom error message in the API controller, the OnError event in the File Manager component always displays the default application error message.
  • Expected Behavior: The File Manager component should display the custom error message returned by the API in case of an operation failure.

  screen1.png


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("");

     }



4 Replies

VM Vishwanathan Muruganantham Syncfusion Team November 4, 2024 02:35 PM UTC

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


Attachment: CustomMessage_ed730a38.zip


RA Radouane November 4, 2024 04:21 PM UTC

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,



VM Vishwanathan Muruganantham Syncfusion Team November 5, 2024 01:10 PM UTC

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.

Feedback: https://www.syncfusion.com/feedback/62806/the-custom-error-message-and-code-not-trigger-the-onerror-event-of-filemanager


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



VM Vishwanathan Muruganantham Syncfusion Team November 22, 2024 01:55 PM UTC

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


Attachment: FileManager27.2.3_5fd8b38a.zip

Loader.
Up arrow icon