How to display errors to client?

Dataprocessor.senddata() did not succeed and rows on grid are not inserted/updated but I don’t get any message explaining why this happened.

What do I have to do in order to display in my webpage that there was an error with the sql?

Thanks

on client side

dp.attachEvent("onAfterUpdate", function(sid, action, tid){ if (action == "error") alert("Something bad happens"); });

By default, server side doesn’t provide any extra info about errors. For dev. purposes you can enable logs in server side code - which will provide details about errors.

It possible to customize server side code and include some more info about error in the response.

Thank you very much for the reply.

For dev purposes I have already checked the log functionality. The error is written in the log file but I was looking for a way to notify dataprocessor about it.

Are there any docs or examples on how we can customize server side code so that we can at least return to dataprocessor the error given by MySQL?

Thanks

you can modify connector/dataprocessor.php

line 158

} catch (Exception $e){ $action->set_status("error"); }

as

} catch (Exception $e){ $action->set_response_text(mysql_error()); $action->set_status("error"); }

Thanks a lot, that worked fine.

Although it would be much safer if we didn’t have to change dataprocessor.php code but just somehow extend it, just like you mention in docs.dhtmlx.com/doku.php?id=dhtm … principles that we can define our own error somehow.

If changes are made in dataprocessor.php then extra caution is required to “redo” these changes when any updates are released from your side.

Just to complete the topic and make it easier for others that might need the same:

In client side i did the following:

function sql_error(node)
{
           alert(node.firstChild.data);
           return false;
}

dp.defineAction("error",sql_error);

Although it would be much safer
Yep, it was missed in the existing design, most probably we will add some kind of onDBError event in next version, so the same scenario will be available without code modification.

Thanks for this, good example. Can the same structure be used to show success message from the connector, from the php I have

	if (mysql_query($InsertSQL))
		$action->success(mysql_insert_id());		
	else {
		$action->set_response_text("Error InsertingTask [$InsertSQL], Please try again");
		$action->error();		

on the client I put

			crewTasksDP.defineAction("error",sql_error);
			crewTasksDP.defineAction("update",sql_success);

function sql_error(node) {
alert(node.firstChild.data);
return false;
}

function sql_success(node) {
alert(node.firstChild.data);
return true;
}

In case of an error it works fine and displays message, but is not working for the success return…

Are you sure that “update” is what comes back?

According to : docs.dhtmlx.com/doku.php?id=dhtm … inciples&s[]=my_error

There are 5 predefined actions:

There are 5 predefined types of response:
update
insert
delete
invalid
error

Could it be “insert” or “delete” ?

Try sending insert & delete to “sql_success” and see.

Unfortunately the docs aren’t very clear on how to handle these actions and I am also a bit confused with them.

Ooops, where is “set_response_text” for the success case?

very clear on how to handle these actions
All default actions already has their logic as part of dataprocessor ( so row will be marked or deleted automatically ) You can attach custom handlers for such actions , to add some extra reaction, but need not care about default processing.