0

I read many topics and many pages of documentation but can't find any easy solution.

How to handle in ExtJS (7.0) Store any unexpected replies from server? For example, when there's no correct JSON data, but there are many PHP error messages.

Here is my extended Store object with modified sync(). If server reply is like correct JSON, then everything is OK. But when server reply is like:

{"success":false,"totalCount":0,"table":[],"errors":["\u041a \u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u044b \u0437\u0430\u043f\u0438\u0441\u0438, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0438\u0445!"],"sysBuild":56,"errorCode":1}<br />
<b>Notice</b>:  Undefined variable: 

There's no any raw data or data about JSON decode error. How can I handle that? And how can I get raw response data in this case?

Ext.define('Ext.data.Store.KCMS', {
    extend: 'Ext.data.Store',
...
    sync: function(options) {
...
        if (needsSync && me.fireEvent('beforesync', operations) !== false) {
            me.isSyncing = true;

            options = options || {};

            if(typeof(options.callback)=="undefined")
                options.callback=function(batch, options) {
                    if(me.visualObject && me.autoStopLoading)
                        me.visualObject.setLoading(false);

*                   console.log("callback");
                    console.log(arguments);
                    console.log(me);
                    console.log(batch.proxy.reader.jsonData);

...
                };
            options.success=function() {
                console.log('success');
                console.log(arguments);
                console.log(me);
            };
            options.failure=function() {
                console.log('failure');
                console.log(arguments);
            };

            me.proxy.batch(Ext.apply(options, {
                operations: operations,
                listeners: me.getBatchListeners(),
                $destroyOwner: me
            }));
        }

        return me;
    }

});
  • You can create your own proxy (Ajax, Rest etc.), and use the [`exception`](https://docs.sencha.com/extjs/7.6.0/classic/Ext.data.proxy.Ajax.html#event-exception) listener. Stop here with the debugger and examine the `response` value to get what you need. – Peter Koltai Jul 30 '23 at 08:15

0 Answers0