From b93fb0d1eb50da9b9676ce2f1ef72799b361316c Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 7 Dec 2016 14:25:35 +0200 Subject: [PATCH] Add exception handling for JSON::ParserError --- libraries/organization_api.rb | 6 +++++- resources/organization.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/organization_api.rb b/libraries/organization_api.rb index 0a3d0eae..1a2cb42f 100644 --- a/libraries/organization_api.rb +++ b/libraries/organization_api.rb @@ -199,7 +199,11 @@ def _do_request(grafana_options, payload=nil) success: grafana_options[:success_msg], unknown_code: grafana_options[:unknown_code_msg] ) - JSON.parse(response.body) + begin + JSON.parse(response.body) + rescue JSON::ParserError + nil + end rescue BackendError nil end diff --git a/resources/organization.rb b/resources/organization.rb index be46f8c0..928d5153 100644 --- a/resources/organization.rb +++ b/resources/organization.rb @@ -1,7 +1,7 @@ actions :create, :update, :delete default_action :create -state_attrs :organization_name +state_attrs :name # Grafana options attribute :host, kind_of: String, default: 'localhost'