Results 1 to 3 of 3

Thread: How to handle Extjs store exceptions?

  1. #1

    Default How to handle Extjs store exceptions?

    Hi,

    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.

  2. #2
    Sencha Premium User
    Join Date
    Dec 2010
    Posts
    277
    Answers
    8

    Default

    in the store reader set messageProperty to detailedMessage. You can either attach a listener to the store load event or add a callback during store load. example:

    Code:
        
        store.load({
            scope: this,
            callback: function (records, operation, success) {
                if (!success && operation.detailedMessage) {
                    Ext.Msg.show({
                        title: 'Error',
                        msg: operation.detailedMessage,
                        modal: true,
                        buttons: Ext.Msg.OK,
                        icon: Ext.Msg.ERROR,
                        closeAction: 'destroy'
                    });
                }
            }
        });


  3. #3
    Sencha User
    Join Date
    Oct 2018
    Location
    Noida
    Posts
    42
    Answers
    8

    Default

    You can optionally add load listener to the store, it will be called in storeload and store exception both scenario. Based on arguments you can understand weather load is successful or failed. You can check code in below fiddle -
    https://fiddle.sencha.com/#view/editor&fiddle/2vbr

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •