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>
..
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.
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
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
Hi,
Unfortunately, it didn't solve the issue "actionFailure missing args".
Do I miss something? What else
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.
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'}
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.
Thanks it work
Hi John,
We are glad that the provided solution worked at your end.