Skip to content

Catch Errors on the Sever Side

Question:
How do I catch errors on the Server side? Errors that come back from the database for example. I can break on them and see that the database is reporting them, but the user never sees them and I'm not sure where to add code to retrieve the errors. 

Solution:
The server errors are not displayed to users by default for security reason unless the DEBUG flag is on (http://phpgrid.uservoice.com/knowledgebase/articles/215888). The workaround is to add global the following fn.ajaxComplete() to display server response. DEBUG flag must be on. 

insert before </body>: 

<pre id="_changes_debug_ajaxresponse"></pre>
<script type="text/javascript">
// *** replace "<PHPGRID>" with your path to phpGrid ***
$(document).ajaxComplete(function( event, xhr, settings ) {
  if ( settings.url.split('?')[0] === "/<PHPGRID>/edit.php" ){  
    // alert( xhr.responseText ); 
    $("#_changes_debug_ajaxresponse").text(xhr.responseText);
  }
});
</script> 

While above code snippet works incredibly well to catch anything Ajax message returned, in the future release, more sophisticated server error handle will also be introduced. 

Feedback and Knowledge Base