Skip to content

Commit

Permalink
fix: more error reporting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed May 22, 2019
1 parent 861c8e8 commit 89346e2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
15 changes: 10 additions & 5 deletions nodes/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ module.exports = function(RED) {
config.server.websocket.CONNECTED
) {
this.setStatusFailed('No Connection');
this.warn('API call attempted without connection to server.');
this.error(
'API call attempted without connection to server.',
message
);

return;
}
Expand All @@ -123,7 +126,7 @@ module.exports = function(RED) {
).replace(/^\/(?:api\/)?/, '');

if (!path) {
node.error('HTTP request requires a valid path.');
node.error('HTTP request requires a valid path.', message);
node.setStatusFailed();
return;
}
Expand All @@ -140,7 +143,8 @@ module.exports = function(RED) {

if (!json.type) {
node.error(
`A WebSocket request requires a 'type' property in the data object.`
`A WebSocket request requires a 'type' property in the data object.`,
message
);
node.setStatusFailed();
return null;
Expand All @@ -151,7 +155,7 @@ module.exports = function(RED) {
json
);
} catch (e) {
node.error(e.message);
node.error(e.message, message);
node.setStatusFailed();
return;
}
Expand All @@ -178,7 +182,8 @@ module.exports = function(RED) {
node.error(
'API Error. ' + err.message
? `Error Message: ${err.message}`
: ''
: '',
message
);
node.setStatusFailed('API Error');
});
Expand Down
5 changes: 3 additions & 2 deletions nodes/call-service/call-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ module.exports = function(RED) {
config.server.websocket.CONNECTED
) {
this.setStatusFailed('No Connection');
this.warn(
'Call-Service attempted without connection to server.'
this.error(
'Call-Service attempted without connection to server.',
message
);

return;
Expand Down
5 changes: 3 additions & 2 deletions nodes/current-state/current-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = function(RED) {
const entityId = parsedMessage.entity_id.value;

if (config.server === null) {
this.node.error('No valid server selected.');
this.node.error('No valid server selected.', message);
return;
}

Expand All @@ -53,7 +53,8 @@ module.exports = function(RED) {

if (!entity.entity_id) {
this.node.error(
`Entity could not be found in cache for entity_id: ${entityId}`
`Entity could not be found in cache for entity_id: ${entityId}`,
message
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions nodes/get-entities/get-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module.exports = function(RED) {
let noPayload = false;

if (config.server === null) {
this.node.error('No valid server selected.');
return null;
this.node.error('No valid server selected.', message);
return;
}

const states = await config.server.homeAssistant.getStates();
Expand Down
4 changes: 2 additions & 2 deletions nodes/get-history/get-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ module.exports = function(RED) {
let useRelativeTime = this.nodeConfig.useRelativeTime;

if (this.nodeConfig.server === null) {
this.node.error('No valid server selected.');
return null;
this.node.error('No valid server selected.', message);
return;
}

if (
Expand Down
10 changes: 6 additions & 4 deletions nodes/poll-state/poll-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ module.exports = function(RED) {
);

if (!pollState.entity_id) {
this.warn(
this.error(
`could not find state with entity_id "${
this.nodeConfig.entity_id
}"`
}"`,
{}
);
this.status({
fill: 'red',
Expand All @@ -102,10 +103,11 @@ module.exports = function(RED) {

const dateChanged = this.calculateTimeSinceChanged(pollState);
if (!dateChanged) {
this.warn(
this.error(
`could not calculate time since changed for entity_id "${
this.nodeConfig.entity_id
}"`
}"`,
{}
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions nodes/render-template/render-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ module.exports = function(RED) {
} = parsedMessage;

if (this.nodeConfig.server === null) {
this.node.error('No valid server selected.');
return null;
this.node.error('No valid server selected.', message);
return;
}

this.setStatusSending('Requesting');
Expand Down

0 comments on commit 89346e2

Please sign in to comment.