improved error handling for server communication