_request(path, payload = null, method = null, raw = false) {
    return new Promise((resolve, reject) => {
      this._ensureLoggedIn().then(() => {
        // Identify which request method we are using (GET, POST, PUT, DELETE) based
        // on the json data supplied and the overriding method
        if (payload !== null) {
          method = method === 'PUT' ? 'PUT' : 'POST';
        } else if (method === null) {
          method = 'GET';
        }

        this._instance.request({
          url: this._url(path),
          method,
          data: payload
        }).then(response => {
          const body = response.data;
          if (body !== null && typeof (body) !== 'undefined') {
            if (typeof (body.meta) !== 'undefined') {
              if (response.status >= 200 && response.status < 400 && body.meta.rc === 'ok') {
                if (raw === true) {
                  resolve(body);
                } else {
                  resolve(body.data);
                }
              } else if (typeof (body.meta.msg) === 'undefined') {
                reject(new Error('generic error'));
              } else {
                reject(new Error(body.meta.msg));
              }
            } else if (response.status >= 200 && response.status < 400) {
              resolve(body);
            } else {
              reject(new Error('invalid status return'));
            }
          } else {
            reject(new Error('empty response data'));
          }
        }).catch(error => {
          reject(error);
        });
      }).catch(error => {
        reject(error);
      });
    });
  }
/**
   * Private function to send out a generic URL request to a UniFi-Controller
   */
Private function to send out a generic URL request to a UniFi-Controller
Private function to send out a generic URL request to a UniFi - Controller
_request(path, payload = null, method = null, raw = false) {
    return new Promise((resolve, reject) => {
      this._ensureLoggedIn().then(() => {
        if (payload !== null) {
          method = method === 'PUT' ? 'PUT' : 'POST';
        } else if (method === null) {
          method = 'GET';
        }
        this._instance.request({
          url: this._url(path),
          method,
          data: payload
        }).then(response => {
          const body = response.data;
          if (body !== null && typeof (body) !== 'undefined') {
            if (typeof (body.meta) !== 'undefined') {
              if (response.status >= 200 && response.status < 400 && body.meta.rc === 'ok') {
                if (raw === true) {
                  resolve(body);
                } else {
                  resolve(body.data);
                }
              } else if (typeof (body.meta.msg) === 'undefined') {
                reject(new Error('generic error'));
              } else {
                reject(new Error(body.meta.msg));
              }
            } else if (response.status >= 200 && response.status < 400) {
              resolve(body);
            } else {
              reject(new Error('invalid status return'));
            }
          } else {
            reject(new Error('empty response data'));
          }
        }).catch(error => {
          reject(error);
        });
      }).catch(error => {
        reject(error);
      });
    });
  }
_request ( path , payload = null , method = null , raw = false ) { return new Promise ( ( resolve , reject ) => { this . _ensureLoggedIn ( ) . then ( ( ) => { if ( payload !== null ) { method = method === 'PUT' ? 'PUT' : 'POST' ; } else if ( method === null ) { method = 'GET' ; } this . _instance . request ( { url : this . _url ( path ) , method , data : payload } ) . then ( response => { const body = response . data ; if ( body !== null && typeof ( body ) !== 'undefined' ) { if ( typeof ( body . meta ) !== 'undefined' ) { if ( response . status >= 200 && response . status < 400 && body . meta . rc === 'ok' ) { if ( raw === true ) { resolve ( body ) ; } else { resolve ( body . data ) ; } } else if ( typeof ( body . meta . msg ) === 'undefined' ) { reject ( new Error ( 'generic error' ) ) ; } else { reject ( new Error ( body . meta . msg ) ) ; } } else if ( response . status >= 200 && response . status < 400 ) { resolve ( body ) ; } else { reject ( new Error ( 'invalid status return' ) ) ; } } else { reject ( new Error ( 'empty response data' ) ) ; } } ) . catch ( error => { reject ( error ) ; } ) ; } ) . catch ( error => { reject ( error ) ; } ) ; } ) ; }
Private function to send out a generic URL request to a UniFi-Controller
Private function to send out a generic URL request to a UniFi - Controller
// Identify which request method we are using (GET, POST, PUT, DELETE) based // on the json data supplied and the overriding method