Example Code of How to Deal with the Error Object

You must implement your own error handing in custom JavaScript code. As an example of how to deal with the error object, the following is a callback function that displays error codes and error messages from CRUD operations.

function callback(request,response){
	var data = "data: ";
	var status = response.status;
	var error = "error: "

	if (status == "OK")
		error += status;
	else
		error += response.errors[0].fac + "\n" + response.errors[0].msg;

	var dataObj = response.data;
	if (dataObj != null)
		data += "Id = " + response.getRowId() + ", Mod Id = " + response.getModId();
	else
		data += "Data is Null";

	alert(data + "\n" + status + "\n" + error);
	}
});

A guideline is to use the error code in error handling rather than the error message. This is recommended because the error code is language independent, but the error message is not. Code like the following only works in English:

if (response.errors[0].msg == "No records found")