const q = require('q')
const _ = require('lodash')
const path = require('path')
const async = require('async')
const request = require('superagent')
const appDir = (path.resolve(__dirname) + '/').replace('lib/utils/', '')
const mainFile = require(appDir + 'index.js')

/**
 * Function to get pages
 * @param  {Object} address Object with IP and Port properties
 * @param  {String} page Page to get. The 'h' in '192.168.1.29/h'
 * @return {Promise}
 */
const getPage = function (address, page) {
  var dfd = q.defer()

  const errors = {
    noParam: 'No param was provided',
    noIp: 'No IP was provided',
    noPage: 'No page was provided',
    noPort: 'No port was provided',
    isOffline: 'Your mining node '+address.ip+':'+address.port+' is offline or was not found'
  }

  const funcArray = [
    (callback) => { // verify params
      var add = _.clone(address)
      if (_.isEmpty(address)) return callback(errors.noParam)
      if (!address.ip) return callback(errors.noIp)
      if (!address.port) return callback(errors.Port)
      if (!page) return callback(errors.Page)

      add.page = page
      callback(null, add)
    },
    (add, callback) => {
      if (callback) {
        request
        .get('http://' + add.ip + ':' + add.port + '/' + add.page)
        .end((err, res) => {

          if (res.status != '200' || err) return callback(err || errors.isOffline)

          callback(null, res.text)
        })
      }
    }
  ]

  async.waterfall(
    funcArray,
    (err, result) => err ? dfd.reject(err) : dfd.resolve(result)
  )

  return dfd.promise
}

module.exports = {
  getPage: getPage
}

@@ -1293,16 +1293,56 @@
 ) =%3E %7B%0A%0A
+          if (err) return callback(err)%0A
         
@@ -1366,23 +1366,16 @@
 != '200'
- %7C%7C err
 ) return
@@ -1388,15 +1388,8 @@
 ack(
-err %7C%7C 
 erro

Fix exception when requesting page was had undefined response