retrieveId method

Future<String> retrieveId()

Get a unique ID from the server via HTTP and initialize with it.

Implementation

Future<String> retrieveId() async {
  try {
    final response = await _buildRequest('id');

    if (response.statusCode != 200) {
      throw Exception('Error. Status:${response.statusCode}');
    }

    return response.body;
  } catch (err, stack) {
    logger.error('Error retrieving ID $err');

    String pathError = '';

    if (_options.path == '/' && _options.host != util.CLOUD_HOST) {
      pathError = " If you passed in a `path` to your self-hosted PeerServer, "
          "you'll also need to pass in that same path when creating a new "
          "Peer.";
    }

    throw Exception('Could not get an ID from the server. $pathError');
  }
}