added error handling code for server errors