Skip to content

Commit

Permalink
small logging changes (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
  • Loading branch information
digitaldan committed Jun 1, 2017
1 parent f613494 commit 35b3ff3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
18 changes: 12 additions & 6 deletions rest.js
Expand Up @@ -9,6 +9,7 @@

var https = require('https');
var config = require('./config');
var logger = require('./log');

/**
* Returns all items
Expand All @@ -23,20 +24,25 @@ function getItems(token, success, failure) {
function getItem(token, itemName, success, failure) {
var options = httpItemOptions(token, itemName);
https.get(options, function (response) {
if (response.statusCode != 200) {
failure({
message: 'Error response ' + response.statusCode
});
return;
}
var body = '';

response.on('data', function (data) {
body += data.toString('utf-8');
});

response.on('end', function () {
if (response.statusCode != 200) {
failure({
message: 'Error response ' + response.statusCode
});
log.info('getItem failed for path: ' + options.path
+ ' code: ' + response.statusCode + ' data: ' + data);
return;
}
var resp = JSON.parse(body);
success(resp);
});

response.on('error', function (e) {
failure(e);
});
Expand Down
7 changes: 0 additions & 7 deletions utils.js
Expand Up @@ -7,12 +7,6 @@
* http://www.eclipse.org/legal/epl-v10.html
*/

/**
* Utility functions.
*/
function log(title, msg) {
console.log('[DEBUG] (' + title + '): ' + msg);
}

/**
* Convert C to F
Expand Down Expand Up @@ -79,7 +73,6 @@ function isEventFahrenheit(event){
event.payload.appliance.additionalApplianceDetails.temperatureFormat === 'fahrenheit';
}

module.exports.log = log;
module.exports.toF = toF;
module.exports.toC = toC;
module.exports.generateControlError = generateControlError;
Expand Down

0 comments on commit 35b3ff3

Please sign in to comment.