Skip to content

Commit 41d82f3

Browse files
author
Dave Conway-Jones
committed
slight tidy of forecast node
does part of the work of #140
1 parent 329dec4 commit 41d82f3

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Diff for: forecast/forecastio.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function(RED) {
2020

2121
function assignmentFunction(node, date, time, lat, lon, forecastioConfig, callback) {
2222
if (forecastioConfig && forecastioConfig.credentials && forecastioConfig.credentials.client_key) {
23-
node.apikey = forecastioConfig.credentials.client_key;
23+
node.apikey = forecastioConfig.credentials.client_key.trim();
2424
} else {
2525
return callback(RED._("forecastio.error.no-credentials"));
2626
}
@@ -85,7 +85,12 @@ module.exports = function(RED) {
8585
if (weather === "Forbidden") {
8686
return callback(RED._("forecastio.error.incorrect-apikey"));
8787
} else {
88-
var jsun = JSON.parse(weather);
88+
var jsun;
89+
try {
90+
jsun = JSON.parse(weather);
91+
} catch (err) {
92+
return callback(RED._("forecastio.error.api-response", { response: weather }));
93+
}
8994
msg.data = jsun;
9095
msg.payload.weather = jsun.daily.data[when].icon;
9196
msg.payload.detail = jsun.daily.data[when].summary;

Diff for: forecast/locales/en-US/forecastio.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"invalid-time": "Invalid time provided",
3434
"invalid-date": "Invalid date provided",
3535
"incorrect-apikey": "Incorrect API key provided",
36-
"invalid-url": "invalid url"
36+
"invalid-url": "invalid url",
37+
"api-response": "Error parsing response from API: __response__"
3738
},
3839
"message": {
3940
"weather-forecast": "Weather Forecast Information",

Diff for: forecast/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "node-red-node-forecastio",
3-
"version" : "0.1.4",
3+
"version" : "0.1.5",
44
"description" : "A Node-RED node that gets the weather forecast from Forecast.io",
55
"dependencies" : {
66
},

0 commit comments

Comments
 (0)