Added code to handle server errors