From 4f195c704a254b1d23750815dd618bced7d51506 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 7 Jun 2019 09:57:34 +1000 Subject: [PATCH] Additional error handling --- lib/builder.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/builder.rb b/lib/builder.rb index 3aeb2ede..7fd4fa6d 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -400,7 +400,7 @@ class CustomWizard::Builder if action['api_body'] != "" begin api_body_parsed = JSON.parse(action['api_body']) - rescue + rescue JSON::ParserError raise Discourse::InvalidParameters, "Invalid API body definition: #{action['api_body']} for #{action['title']}" end api_body = CustomWizard::Builder.fill_placeholders(JSON.generate(api_body_parsed), user, data) @@ -408,8 +408,9 @@ class CustomWizard::Builder result = CustomWizard::Api::Endpoint.request(action['api'], action['api_endpoint'], api_body) - if result[0].has_key? 'error' - updater.errors.add(:send_message, result[0]['error']) + if error = result['error'] || (result[0] && result[0]['error']) + error = error['message'] || error + updater.errors.add(:send_to_api, error) else ## add validation callback end