abstract out handling of server response