Improve error handling when something goes wrong with the server