3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Plugins/Wttr: return result as-is if JSON decode fails

This commit is contained in:
Pragmatic Software 2020-03-20 09:45:12 -07:00
parent 0e1a496001
commit 0dce5861f3

View File

@ -123,7 +123,8 @@ sub get_wttr {
if ($response->is_success) { $json = $response->decoded_content; } if ($response->is_success) { $json = $response->decoded_content; }
else { return "Failed to fetch weather data: " . $response->status_line; } else { return "Failed to fetch weather data: " . $response->status_line; }
my $wttr = decode_json $json; my $wttr = eval { decode_json $json };
return $json if $@; # error decoding json so it must not be json -- return as-is
if (exists $wttr->{nearest_area}) { if (exists $wttr->{nearest_area}) {
my $areaName = $wttr->{nearest_area}->[0]->{areaName}->[0]->{value}; my $areaName = $wttr->{nearest_area}->[0]->{areaName}->[0]->{value};