You might be able to do something with returning a HTTP header, such as a "404 Not Found", etc., then do a check in your AJAX handler JavaScript:
if ( request.readyState == 4 ){ // 4 is "complete"
if ( request.status == 200 ){
// HTTP OK, carry out your normal Ajax processing
// ...
}else{
// something went wrong, report the error
error( "HTTP "+request.status+". An error was ยป
encountered: "+ request.statusText );
}
}
I have not tested this, though, so I'm not sure how well it does or does not work.
If you are actually using the "X" part of "AJAX" and returning valid XML data, then it should be a fairly simple matter to include a "status" element or attribute in that data, and have your JavaScript check that value to decide whether or not an error occurred.