function checkClusterConnection()

in Code.gs [44:62]


function checkClusterConnection(host) {
  isValidHost(host);
  var url = [(host.use_ssl) ? 'https://' : 'http://',
             host.host,':',host.port,'/'].join('');
  var options = getDefaultOptions(host.username,host.password);
  options['muteHttpExceptions'] = true;
  try {
    var resp = UrlFetchApp.fetch(url, options);
    if(resp.getResponseCode() != 200) {
      var jsonData = JSON.parse(resp.getContentText());
      if(jsonData.message == 'forbidden') {
        throw "The username and/or password is incorrect."
      }
      throw jsonData.message;
    }
  } catch(e) {
    throw 'There was a problem connecting to your cluster. Please the connection details and try again.'
  }
}