PDA

View Full Version : Is it possible to send custom error message if the load request of Store fails



Spider
24 Nov 2007, 9:40 AM
Hi

I am using Ext.data.Store for fetching different options of a Combo Box at multiple places in my app. In the Reader configured with the Store we can specify the schema for the response received by the configured Proxy. But if there is an error/exception at the server side i am only able to know whether the AJAX request succeded or failed by the checking the success parameter in the callback function specified at the time of load call.

I have seen the different arguments we can have in the callback function of a load's call or an event handler specified for the load event.

I may be missing something, it will be very helpful in the app i am developing.

tryanDLS
24 Nov 2007, 9:50 AM
You can add a handler for the loadexception event if you're trying to catch status code that are not in 200-299.

hendricd
24 Nov 2007, 9:56 AM
There are a number of ways to handle it, but as a practical matter, every store should have a 'loadexception' event defined. If anything goes wrong during the Ajax request or during eval of the response, the loadexception event will fire.

If your serverScript decides it can't handle the request properly, the easiest thing to do is return an 'unseccessful' HTTP status in the response (say 410 or something). Then, the stores' loadexception event would be raised.

Spider
27 Nov 2007, 1:00 AM
Thanks tryanDLS and hendricd for suggestions

I added an event handler for the loadexception event. Tested various possible error scenarios.
The loadexception event handler takes dataproxy, data, callback and exception as arguments.
From callback. status and statusText i was able to know about the error codes and descriptions.

But i am trying to send the root exception cause or if possible the whole stack trace in the json response from the server.
In my existing app which use jsps i have an error page which have a details button, which when clicked shows the whole
error stack trace to the user. The user can simply copy that stack trace and send it to the Support team.

I was wondering whether i will be able to do the same thing with extJS.

Maybe using callback.responseText i might be able to do this.
Please let me know your views.

blueice
27 Nov 2007, 1:50 AM
in my test ,no process,and can't process ,

it's be treated as empty recordset.

hendricd
27 Nov 2007, 7:53 AM
@Spider - Sure, just include your serverSide stack trace in the JSON reponse:


{success:false,
criticalException:true,
stackTrace:[ ]
}

.. and send it back with a 409? http status. Then loadexception will see the response, and you can handle it any way you want.