PDA

View Full Version : The store prefetch callback is invoked even if the request failed



zerkms
28 Nov 2012, 7:11 PM
Affected versions: 4.1.x

The current Ext.data.proxy.Server::processResponse() implementation invokes the callback regardless of if the operation completed successfully or not.

I've found this bug when accidentally refreshed the chrome tab in the middle of the store request (in this case all the ajax requests are cancelled by browser) and caught an exception - because my code expects that `prefetch` callback is invoked only if a request successful.

Possible solution: presumably the callback call

if (typeof callback == 'function') {
callback.call(scope || me, operation);
}

should be moved to the end of `success === true` block

mitchellsimoens
28 Nov 2012, 7:55 PM
callback will always fire. success will only fire on success. failure will only fire on failure.

zerkms
28 Nov 2012, 8:03 PM
callback will always fire. success will only fire on success. failure will only fire on failure.

The documentation states "Fires whenever records have been prefetched."
(c) http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-event-prefetch

So if the request fails - I expect the `prefetch` event not to be fired

mitchellsimoens
29 Nov 2012, 5:21 AM
Now you are talking about an event not a callback.

zerkms
29 Nov 2012, 11:31 AM
Right, they are connected. The event's callback is the one I was talking in the first post.

zerkms
3 Dec 2012, 6:20 PM
So, any thoughts?