result.then(function (resolved) { debug('Promise resolved'); if (resolved) { that.emit('data', elasticio.messages.newMessageWithBody(resolved)); } that.emit('end'); }).catch(function (err) {
request(csvURL, function (error, response, body) { console.log('Have got response status=%s headers=%j', response.statusCode, response.headers); console.log('Response body is:\n--------\n%j...\n--------', body.substring(0,128)); if (response.statusCode != 200) { that.emit('error', 'Unexpected response code code=' + response.statusCode); throw Error('Unexpected response code code=' + response.statusCode); } else { that.emit('data', messages.newMessageWithBody({'csv': body})); } that.emit('end'); });