View Full Version : Whats wrong with my error handling code?

1 Mar 2010, 7:35 AM
I am using the following technique to display serverside errors to the client when things
go bump:

var sub_menu = new Array(
text: 'Complete Task',
handler: function(){
url: 'services/index.php/application/task/approve',
failure: function(form, action){
alert('Error handler has been triggered');

The script is being invoked according to FireBug and the results are what I expected:

{"success":false,"errors":{"reason":"This is a test to ensure that error recovery operations are working effectively."}}

What else am I missing about how the error handlers are triggered on the client side? Do I need to set an error code in the headers as well or something???

This is what the server side code is doing:

$message = 'This message is set somewhere before the following code';

$result['success'] = false;
$result['errors']['reason'] = $message;

header('Content-Type: application/json');
echo json_encode($result);


1 Mar 2010, 8:22 AM
The success and failure handlers are for determining whether you could connect to your server or not (or for some other server-side failure).

To handle your situtation:

url: 'services/index.php/application/task/approve',
success: function(response, options)
var data = Ext.util.JSON.decode(response.responseText);
if (data.success == true){
else {
failure: function(response, options){
alert('Server-side failure with status code: ' + response.status);