1
votes

I am using Extjs 6.5.3 classic toolkit. I am having store for grid. I want to handle store load exceptions. How can I handle this?

My store is like this:

Ext.define('RUI.store.ProjectListStore', {
    extend: 'Ext.data.Store',
    sortOnLoad: false,
    pageSize:RUIRamboConstants.DEFAULT_PAGE_SIZE,
      proxy : {
        type : 'ajax',
        actionMethods: {
            read: 'POST'
        },
        url:    'api.do',
        reader: {
            rootProperty: 'List',
            type: 'json',
            isURLConvert : true,
            totalProperty: 'TotalRecords',

        }
    }

});  

I get following response from server:

{
  "limit": 10,
  "page": 1,
  "start": 0,
  "TotalRecords": 2,
  "userFilterId": 0,
  "List": [
    {
      "id": 1,
      "name" : "abc"
    },
    {
      "id": 1926722,
     "name" : "xyz"
    }
  ]
}

When failure:

{
  "returnCode": 1,
  "messageKey": null,
  "detailedMessage": null,
  "exception": null,
  "browser": "Mozilla 5.0 (Windows)",
  "customParams": null,
  "errorMessages": [
    {
      "messageKey": "duplicate",
      "detailedMessage": "Duplicate."
    }
  ],
  "success": false
}

I want to catch this failure and want to show message as "Duplicate".

Please help!!

Thank you in advance.

1
You will need to extract that specific flag from response and then show it on UI. How are you calling store is it autoload/you called it manually ?Tejas
I am calling it manuallyPriyanka Kakade

1 Answers

0
votes

You can listen to your store's load event, and then check if the response was successful or not, something like this:

listeners: {
    load: function(store, records, success) {
        if (!success) {
            Ext.Msg.show({
                title: 'Error',
                message: recs[0].data.errorMessages[0].detailedMessage
            })
        }

    }
}

Working Fiddle