actionFailure missing args

Hi,

The args.error[0].error in actionFailure returns  "Error at https://localhost:44312/js/ej2/ej2.min.js:1:763649" instead of actual error from controller.

[Controller]

public ActionResult Insert([FromBody] CRUDModel<Network> value)
{
        if (_context.Networks.Any(x => x.Name == value.Value.Name))

        {
            Exception ex = new Exception("Network exists!");
            throw ex;
        }
...


[View]

...
            <ejs-grid id="Grid" dataSource="@ViewBag.DataSource" actionBegin="actionBegin" actionComplete="actionComplete" actionFailure="actionFailure" allowFiltering="true" allowSorting="true" allowPaging="true" allowExcelExport="true" allowPdfExport="true" toolbarClick="toolbarClick"
                      toolbar="@(new List<string>() { "Add", "Edit", "Cancel", "Update", "ExcelExport", "PdfExport", "CsvExport" })">
                <e-grid-pagesettings pageSize="15"></e-grid-pagesettings>
                <e-data-manager adaptor="UrlAdaptor" url="@Url.Action("UrlDatasource", "Networks")" insertUrl="/Networks/Insert" updateUrl="/Networks/Update"></e-data-manager>
                <e-grid-editSettings allowAdding="true" allowDeleting="false" allowEditing="true" mode="Dialog" template='#dialogtemplate'></e-grid-editSettings>
                <e-grid-loadingIndicator indicatorType="Spinner"></e-grid-loadingIndicator>
                <e-grid-filtersettings type="CheckBox"></e-grid-filtersettings>
                <e-grid-columns>
                    <e-grid-column field="NetworkId" headerText="ID" type="number" visible="false" width="25" isPrimaryKey="true"></e-grid-column>
                    <e-grid-column field="Name" headerText="Name" type="string" allowFiltering="true" allowSorting="true" width="120"></e-grid-column>
                </e-grid-columns>
            </ejs-grid>

..



9 Replies

JC Joseph Christ Nithin Issack Syncfusion Team November 14, 2023 09:22 AM UTC

Hi Lucian,


  Greetings from Syncfusion support.


We are glad to announce that we have included we have included the fix for “In actionFailure, failure message is not sent properly in latest version” in the latest version 23.1.41. We suspect you are using a older version of the EJ2, hence we suggest you to update to the latest version. To obtain a custom error message from the server-side within the actionFailure event argument during a fetch operation, use the text() method within the await statement to retrieve the custom error message from the server side. Please refer the below code example and sample for more information.


 

 

<script>

    async function actionFailure(args) {

        if (args && args.error && args.error[0] && args.error[0].error) {

            try {

                const response = await args.error[0].error.text();

                const errorMessage = response.split("Exception:")[1].split('\n')[0].slice(1);

               alert(errorMessage);

            } catch (error) {

                console.error("Error reading the error message: " + error);

            }

        }

    }

</script>

 


Regards,

Joseph I.



LC Lucian Calin November 14, 2023 09:28 AM UTC

Dear Joseph,


Thank you for your reply!

I am using Syncfusion.EJ2.AspNet.Core version 23.1.44.

How can I update the ej2.min.js? It looks that it doesn't update automatically.


Best regards,

Lucian



JC Joseph Christ Nithin Issack Syncfusion Team November 20, 2023 09:22 AM UTC

Hi Lucian,


  Based on your query, you want to update the ej2.min.js file in your application. Please refer the below documentation where we have provided details on how to update the cdn link of the ej2.min.js file.


  Documentation: https://ej2.syncfusion.com/aspnetcore/documentation/grid/getting-started-core#add-stylesheet-and-script-resources


  You can also refer the below documentation on details of how to update the script using different approaches if you are not using the cdn link.


Documentation: https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references



LC Lucian Calin November 20, 2023 05:55 PM UTC

Hi,


Unfortunately, it didn't solve the issue "actionFailure missing args".

Do I miss something? What else 



JC Joseph Christ Nithin Issack Syncfusion Team November 23, 2023 08:48 PM UTC

Hi Lucian,


  Before proceeding with the solution, kindly share the below details.


  • Complete grid rendering code.

  • A Simple sample that demonstrates the issue you are experiencing.

  • A video demo of the requirement.

  • Screenshot of the console window, if any script error is thrown.

  • Screenshot of the network tab details of the request.

  • Syncfusion package version you are using.



JT John Taylor December 5, 2023 03:58 PM UTC

Hi Joseph,


I'm having the same problem.

I am using version 23.1.44. When I throw an exception in the Controller, I cannot catch the custom  error message in ActionFailure either. I added args below. ( for function actionFailure(args) )

{error: Array(1), name: 'actionFailure'}


    1. error: Array(1)
      1. 0:
        1. error: Response
          1. body: ReadableStream
            1. locked: false
            2. [[Prototype]]: ReadableStream
              1. locked: (...)
              2. Symbol(Symbol.toStringTag): "ReadableStream"
          2. bodyUsed: false
          3. headers: Headers
          4. ok: false
          5. redirected: false
          6. status: 500
          7. statusText: ""
          8. type: "basic"
          9. url: "https://localhost:44301/ClientOutgoingPayment/PayClientExpenseByBankAccountTransaction"
          10. [[Prototype]]: Response
            1. body: (...)
            2. bodyUsed: (...)
            3. headers: (...)
            4. ok: (...)
            5. redirected: (...)
            6. status: (...)
            7. statusText: (...)
            8. text: ƒ text()
              1. length: 0
              2. name: "text"
              3. arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:3:28) at t.actionFailure (https://localhost:44301/ClientOutgoingPayment/ExpensePaymentWithBank:326:9) at e.notify (https://cdn.syncfusion.com/ej2/23.1.44/dist/ej2.min.js:10:744794) at e.trigger (https://cdn.syncfusion.com/ej2/23.1.44/dist/ej2.min.js:10:774450) at e.editFailure (https://cdn.syncfusion.com/ej2/23.1.44/dist/ej2.min.js:10:9701107) at e.edFail (https://cdn.syncfusion.com/ej2/23.1.44/dist/ej2.min.js:10:9697843) at https://cdn.syncfusion.com/ej2/23.1.44/dist/ej2.min.js:10:9697711]
              4. caller: (...)
            9. type: (...)
            10. url: (...)
            11. Symbol(Symbol.toStringTag): "Response"
        2. [[Prototype]]: Object
          1. __proto__: (...)
      2. length: 1
      3. [[Prototype]]: Array(0)
        1. length: 0
    2. name: "actionFailure"


JC Joseph Christ Nithin Issack Syncfusion Team December 7, 2023 10:42 PM UTC

Hi John,


Greetings from Syncfusion support


We understand that you've noticed a change in the behavior of the actionFailure event in the latest version of our product. I'd like to clarify that in the older version, we indeed utilized XMLHttpRequest for the AJAX operation. However, in our latest version, we have transitioned to using the fetch operation. As a result, you won't find XMLHttpRequest when using the fetch operation.


To obtain a custom error message from the server-side within the actionFailure event argument during a fetch operation, you can make use of the text() method within the await statement to retrieve the custom error message from the server side.  Please refer the code snippet for more information.


 

<script>

    async function actionFailure(args) { //actionFailure event of Grid

        if (args && args.error && args.error[0] && args.error[0].error) {

            try {

                const response = await args.error[0].error.text();

                const errorMessage = response.split("Exception:")[1].split('\n')[0].slice(1);

                alert(errorMessage);

            } catch (error) {

                console.error("Error reading the error message: " + error);

            }

        }

    }

</script>

 



Regards,

Joseph I.



JT John Taylor December 9, 2023 08:16 PM UTC

Thanks it work



JC Joseph Christ Nithin Issack Syncfusion Team December 11, 2023 06:06 PM UTC

Hi John,


  We are glad that the provided solution worked at your end.


Loader.
Up arrow icon