Results 1 to 2 of 2

Thread: How to handle request errors on Store

  1. #1
    Sencha User
    Join Date
    Jan 2013
    Location
    Salvador, Bahia - Brazil
    Posts
    35

    Default How to handle request errors on Store

    I'm trying to show an error information in my app.
    I tried 3 different cases and in all is the same situation.
    404 error, JSON Reader error and nonexistent URL.
    In my Store added a load listener to verify the success and the store.isLoaded().
    In all cases the success returns false but store.isLoaded() returns true and I think it makes a blank page load.
    I think that should show the emptyText list property since it was not loaded any content.


    How to handle it?
    I'm calling Store.load() in the list initialize method.

    Code:
    Ext.define('Amib.view.EventsList', {
        extend: 'Ext.dataview.List',
        xtype: 'eventslist',
    
    
        config: {
            cls: 'eventslist',
            disableSelection: true,
            height: '100%',
            scrollable: 'vertical',
            store: 'events',
            itemTpl: new Ext.XTemplate(
                '<div class="title">{title}</div>',
                '<div class="date">{date}</div>',
                '<div class="location">{location}</div>',
                '<tpl if="link">',
                    '<div class="more">',
                        '<input type="button" class="link" id="{link}" value="More Info"/>',
                    '</div>',
                '</tpl>'
            ),
            listeners: {
                initialize: function (list) {
                    list.getStore().load();
                },
                itemtap: function (list, index, target, record, event) {
                    if (Ext.get(event.target).hasCls('link') && !Ext.isEmpty(record.get('link'))) {
                        Amib.app.getController('Base').openURL(record.get('link'), true);
                    }
                }
            }
        }
    });
    Code:
    Ext.define('Amib.store.Events', {
        extend: 'Ext.data.Store',
        config: {
            autoLoad: false,
            model: 'Amib.model.Event',
            storeId: 'events',
            proxy: {
                type: 'ajax',
                url: 'http://404-error.com/test',
                noCache: false,
                enablePagingParams: false,
                reader: {
                    type: 'json',
                    rootProperty: 'items'
                }
            }
        }
    });

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,449
    Answers
    3997

    Default

    The loaded property on the store will be set to true regardless of the request successful. Look at the docs for the load method, you can provide a callback function and one of the arguments is success:

    Code:
    store.load({
        callback: function(records, operation, success) {
            // the operation object contains all of the details of the load operation
            console.log(records);
        },
        scope: this
    });
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Fullstack Engineer
    ________________
    Modus Create is based on the model of an open source team. We’re a remote, global team of experts in our field. To find out more about the work we do, head over to our website.

    Check out my GitHub:
    https://github.com/mitchellsimoens

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
  •