Skip to content

Commit

Permalink
Fixed crash in weatherunderground on malformed/missing server response
Browse files Browse the repository at this point in the history
  • Loading branch information
naofireblade committed Oct 11, 2019
1 parent 43d17f8 commit bb59ee7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,7 @@
* Added new weather underground api (post January 2019)

## 2.8.1
* Fixed crash in openweathermap api that occured since v2.8.0
* Fixed crash in openweathermap api that occured since v2.8.0

## 2.8.2
* Fixed crash in weatherunderground on malformed/missing server response
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

This is a weather plugin for [homebridge](https://github.com/nfarina/homebridge) that features current observations, daily forecasts and history graphs for multiple locations and services. You can download it via [npm](https://www.npmjs.com/package/homebridge-weather-plus).

If you like this plugin, I would be very grateful for any support to stay awake while coding:
<a href="https://www.buymeacoffee.com/2D1nUuK36" target="_blank"><img src="https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
If you like this plugin, I would be very grateful for your support:

<a href="https://www.buymeacoffee.com/2D1nUuK36" target="_blank"><img width="140" src="https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/orange_img.png" alt="Buy Me A Coffee"></a>

Feel free to leave any feedback [here](https://github.com/naofireblade/homebridge-weather-plus/issues).

Expand Down
17 changes: 12 additions & 5 deletions api/weatherunderground.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ class WundergroundAPI {
request(encodeURI(queryUri), function (err, response, body) {
if (!err) {
// Current weather report
const jsonObj = JSON.parse(body);
debug(JSON.stringify(jsonObj, null, 2));

weather.report = that.parseReport(jsonObj);
callback(null, weather);
try
{
const jsonObj = JSON.parse(body);
debug(JSON.stringify(jsonObj, null, 2));

weather.report = that.parseReport(jsonObj);
callback(null, weather);
} catch (e) {
debug("Error retrieving weather report and forecast");
debug("Error Message: " + e);
callback(e);
}
} else {
debug("Error retrieving weather report and forecast");
debug("Error Message: " + err);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-weather-plus",
"version": "2.8.1",
"version": "2.8.2",
"description": "A comprehensive weather plugin for homekit with current observations, forecasts and history.",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit bb59ee7

Please sign in to comment.