improved handling of error responses from server