Manage Exception ActionFailure

hi,

in onactionfailure event when api return and exception the arsg.error is

error.jpg

the api return a badrequest with this  json body 

{
    "statusCode": 400,
    "message": "Alias: Es obligatorio informar un nombre"
}

not sure what is the problem.

version 27.1.57

attach image postman result 

error2.jpg

thank's in advance


10 Replies 1 reply marked as answer

PS Prathap Senthil Syncfusion Team November 5, 2024 03:01 AM UTC

Hi Sergio Cabello,

Based on the reported problem we seem that you have used the WebApiAdaptor, but the response you shared is not correct when using the WebApiAdaptor. The response object should contain the properties Items and Count, where Items is the collection of entities, and Count is the total number of entities. It seems that the response in your code is not structured correctly, which is why you are facing this issue. Please ensure that your project returns the correct response. The sample response object should look like this. Kindly refer to the documentation below for more information.


Reference: https://blazor.syncfusion.com/documentation/data/adaptors#web-api-adaptor

{

    "Items": [{..}, {..}, {..}, ...],

    "Count": 830

}

 

 


Regards,
Prathap Senthil



SC Sergio Cabello November 5, 2024 02:53 PM UTC

hi Prathap,


i use odatav4adaptor

the problem is that the action update, for any reason throw one exception in api, the api has a global filter for manage exceptions and throw one exception 

           var response = new
           {
               StatusCode = 400,
               Message = mensajeConcatenado
           };
           context.Result = new BadRequestObjectResult(response);
           context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
           context.ExceptionHandled = true;


but in onactionfailure event from SFGRID, the args.error has an error from serialization, 



thank's




PS Prathap Senthil Syncfusion Team November 6, 2024 09:02 AM UTC

Based on the reported problem, we suspect that the action failure event is throwing the error message, but you are getting the Serialization type in args.error. Could you please confirm if this is the issue you reported?



SC Sergio Cabello replied to Prathap Senthil November 6, 2024 01:17 PM UTC

yes Prathap this is the problem 



PS Prathap Senthil Syncfusion Team November 7, 2024 11:30 AM UTC

Based on the reported problem, this is a known issue, and we have classified it as a bug. Different types of exceptions may be thrown from the server side, so we have implemented support for sending exceptions directly to be processed in the ProcessResponse method. We kindly request that you address your requirements using this approach.

We have also logged an issue titled “To get the exception details at the DataAdaptor/DataManager level” for the same. Thank you for taking the time to report this issue and helping us to improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and this fix will be included in our upcoming patch release which is expected to be rolled out on or before 19th November 2024.


You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.     


https://www.syncfusion.com/feedback/62682/to-get-the-exception-details-at-the-dataadaptor-datamanager-level


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”


Until then we appreciate your patience.



PS Prathap Senthil Syncfusion Team November 25, 2024 04:42 AM UTC

Thanks for your patience,

We are glad to announce that, we have included the fix for the issue “To get the exception details at the DataAdaptor/DataManager level” in our 27.2.3 release.  So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the NuGet package for the latest fixes and features below.


NuGet: https://www.nuget.org/packages/Syncfusion.Blazor.Grid


Release notes: https://blazor.syncfusion.com/documentation/release-notes/27.2.3


Root Cause: The issue arises because, in the previous implementation, only the exception message was being passed to the SendRequest method. The customer requested more detailed exception information, which was missing in the previous implementation.

Corrective Actions Taken: We updated the SendRequest method to pass the full exception instead of just the exception message. By doing this, we ensure that all relevant exception details are captured.

We thank you for your support and appreciate your patience in waiting for this release.



SC Sergio Cabello December 27, 2024 09:00 AM UTC

hi Team,

i think that this issue is not resolved, with previous versions over 27.1.48 the exception message arrive to client

but in the last versions an error ocurred in serialize the exception, last version from 27.x i can't see the exception message for manage in client application

error_notmanage.jpg

i attached a demo for reproduce, in server project in controller i force an exception


  [EnableQuery]

  public IActionResult Get(CancellationToken token)

  {

      throw new Exception("FORCE ERROR");

      GetData();

      IQueryable<OrgUnit> tOrgUnits = orgUnits.AsQueryable();

      return Ok(tOrgUnits);

  }


best regards


Attachment: demofail_3976ae87.zip


PS Prathap Senthil Syncfusion Team January 14, 2025 11:12 AM UTC

Based on the reported problem, we would like to clarify that in earlier versions, serialization errors were sent differently. To address this issue, we have implemented support for sending exceptions directly, allowing them to be processed in the ProcessResponse method.

When an issue occurred previously, the ProcessResponse method was triggered, but exception details were not available. However, in the latest version, we have ensured that complete exception details are returned, allowing the ProcessResponse method to capture and display them. If you still want to retrieve exception details, we recommend using the ProcessResponse method to get the error information. Kindly refer to the attached sample for your reference.



Previous version



Version : 27.2.3






Attachment: BlazorDataGridODatav4_415b9bdf.zip


SC Sergio Cabello January 16, 2025 06:49 PM UTC

I already understand what you are proposing, it was more direct and simple to handle the final message for the client directly in the onactionfailure method,


I see that there is another method called ProcessCrudResponse, which I assume is the one that is executed when the error occurs not in the data loading but in the add, delete and modification operations.


Could you tell me what type of errors would go directly through the onactionfailure method, errors directly in the client perhaps?



PS Prathap Senthil Syncfusion Team January 20, 2025 01:12 PM UTC

We would like to inform you that we are previously using a standard exception in the catch block to return error messages. To enhance this process, we have implemented support for sending exceptions directly, allowing them to be processed in the ProcessResponse method. We kindly request that you meet the requirements using this approach to achieve detailed error information.


For CRUD operation failures, you will need to use the ProcessCrudResponse method by sending exceptions directly, which allows them to be processed. Please refer to the code snippet and sample provided below for your reference. This is a possible way to obtain detailed error information using the OnActionFailure event.


  public override async Task<object> ProcessCrudResponse<T>(object data, DataManagerRequest queries)

  {

      if (data is HttpResponseMessage response)

      {

          // Check for error status codes

          if (!response.IsSuccessStatusCode)

          {

              string errorMessage = await response.Content.ReadAsStringAsync();

              Console.WriteLine($"HTTP Error: {response.StatusCode}");

              Console.WriteLine($"Response Message: {errorMessage}");

 

              // Throw a detailed exception

              throw new HttpRequestException($"Error: {response.StatusCode} - {errorMessage}");

          }

      }

      // Process successful response

      var ActualReturnValue = await base.ProcessResponse<T>(data, queries);

      return ActualReturnValue;

 

  }



Attachment: DataGridCRUD_21c728c9.zip

Marked as answer
Loader.
Up arrow icon