Reputation: 1207
The following proxy has been throwing listener
exceptions at sporadic moments. I added a timeout:100
to try and recreate the error and it successfully throws it every time.
However the error sometimes occurs for a request under the default of 30 seconds.
Is there anything else, besides the timeout, that would cause the listener
exceptions to be thrown? There is nothing informative in the error logs.
proxy: {
type: 'rest',
url: '/data/identity',
reader: {
type: 'json',
successProperty: 'success',
messageProperty: 'message'
},
writer: {
type: 'json',
writeAllFields: true
},
listeners: {
exception: function(proxy, response, operation, eOpts){
if(operation.action === "read"){
Ext.Msg.alert('Error Retrieving', response.responseText);
}else if(operation.action === "create"){
Ext.Msg.alert('Error Creating', response.responseText);
}else if(operation.action === "update"){
Ext.Msg.alert('Error Updating', response.responseText);
}
}
}
}
Upvotes: 0
Views: 531
Reputation: 19895
The operation
object contains information about the error. It has a method getError()
to get a description of the error. This would probably show you the error message you are looking for :
var error = operation.getError()
if(error.status && error.statusText){
Ext.Msg.alert('Error', 'Error ' + error.status + ': ' + error.statusText)
}
This is the code I use in my proxy. In addition to display the error thrown during the operation
, it also displays any error that happened on the server side (I catch them and send them in the msg
property of the json data). The reason why I check for navigator.onLine
is that my application uses Application Cache.
listeners: {
exception: function(proxy, response, operation){
var error = operation.getError(),
errorMsg;
if(!navigator.onLine){
errorMsg = Lang._('You are not connected to internet.')
} else if(Ext.isObject(error)){
if(error.status && error.statusText)
errorMsg = 'Error ' + error.status + ': ' + error.statusText
else
errorMsg = Ext.encode(error)
} else if(response.responseText) {
var json = Ext.decode(response.responseText);
errorMsg = json.msg
}
Ext.Msg.show({
title: Lang._('Error loading external data'),
msg: errorMsg,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
})
}
}
Upvotes: 3