node-red-contrib-spark
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -0,4 +1,9 @@ | ||
#### 2.0.1: Maintenance Release | ||
- updated error handling of api node | ||
- updated swagger definitions | ||
#### 2.0.0: Major Release | ||
- Updated all node inline documentation and label formats | ||
- updated all node inline documentation and label formats | ||
- api node now sends array responses as individual sequential messages | ||
@@ -16,3 +21,3 @@ - parse node rebuilt to allow more than 1 property to be parsed from payload | ||
- simplified parser node | ||
- updated swagger definition files to include new APIs for people, organizations, licenses, and roles. | ||
- updated swagger definition files to include new APIs for people, organizations, licenses, and roles | ||
@@ -19,0 +24,0 @@ #### 1.0.4: Maintenance Release |
{ | ||
"name": "node-red-contrib-spark", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Node-RED Nodes to integrate with the Cisco Spark API", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -44,11 +44,7 @@ module.exports = function(RED) { | ||
processResponse(msg, response); | ||
}, function(errMessage) { | ||
if(errMessage) { | ||
processError(new Error(errMessage)); | ||
} else { | ||
processError(new Error('swagger client returned undefined error')); | ||
} | ||
}, function(err) { | ||
processError(msg, err); | ||
}); | ||
} else { | ||
processError(new Error('spark api token or swagger client invalid or not defined')); | ||
node.error('spark api token or swagger client invalid or not defined'); | ||
} | ||
@@ -162,2 +158,12 @@ } | ||
// if response is from a delete... | ||
if(newMsg.status === 204) { | ||
newMsg.payload = {}; | ||
// send message | ||
node.send(newMsg); | ||
return null; | ||
} | ||
// if response.data | ||
@@ -167,12 +173,2 @@ if(response.hasOwnProperty('data')) { | ||
// if response is from a delete... | ||
if(newMsg.status === 204) { | ||
newMsg.payload = {}; | ||
// send message | ||
node.send(newMsg); | ||
return null; | ||
} | ||
// if empty response... | ||
@@ -207,3 +203,3 @@ if(typeof data === 'string' && (data === '' || data === '{}')) { | ||
// if response is array of items | ||
if(typeof data === 'object' && data.hasOwnProperty('items') && data.items instanceof Array) { | ||
if(typeof data === 'object' && data.hasOwnProperty('items') && data.items instanceof Array && data.items.length > 0) { | ||
@@ -247,2 +243,10 @@ // if as multiple messages | ||
// else, if response is empty array of items | ||
else if(typeof data === 'object' && data.hasOwnProperty('items') && data.items instanceof Array) { | ||
newMsg.payload = {}; | ||
// send message | ||
node.send(newMsg); | ||
} | ||
// else, response is single item | ||
@@ -276,9 +280,55 @@ else { | ||
function processError(err) { | ||
if(err && typeof err === 'object' && err.hasOwnProperty('message')) { | ||
// show error | ||
node.error(err.message); | ||
function processError(msg, response) { | ||
if(response && typeof response === 'object') { | ||
var status; | ||
var data; | ||
var errMessage; | ||
var trackingId; | ||
// capture status | ||
if(response.hasOwnProperty('status')) { | ||
status = response.status; | ||
} else { | ||
status = 500; | ||
} | ||
// capture response body | ||
if(response.hasOwnProperty('data')) { | ||
data = response.data; | ||
// if response.data is valid... | ||
if(typeof data === 'string') { | ||
// attempt parsing of json | ||
try { | ||
data = JSON.parse(data); | ||
} | ||
catch(err) { | ||
node.error('error ' + status + ': ' + err.message || 'undefined'); | ||
// set node status | ||
setNodeStatus('error'); | ||
return null; | ||
} | ||
if(data.hasOwnProperty('trackingId')) { | ||
trackingId = data.trackingId; | ||
} else { | ||
trackingId = 'unknown'; | ||
} | ||
if(data.hasOwnProperty('message')) { | ||
errMessage = data.message; | ||
} else { | ||
errMessage = 'unknown'; | ||
} | ||
node.error('error ' + status + ': ' + errMessage + ' | trackingId: ' + trackingId); | ||
} | ||
} else { | ||
node.error('error ' + status + ': undefined error'); | ||
} | ||
} else { | ||
node.error('unknown error'); | ||
node.error('error: unknown API response'); | ||
} | ||
@@ -285,0 +335,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
18503
1083751