lib/brightbox-cli/error_parser.rb in brightbox-cli-1.1.0 vs lib/brightbox-cli/error_parser.rb in brightbox-cli-1.2.0

- old
+ new

@@ -15,18 +15,22 @@ parse_http_error(socket_error) end end def parse_http_error(e) - if e.respond_to?(:response) and e.response.respond_to?(:body) - json_response = JSON.parse(e.response.body) rescue {} - extract_response_from_json(json_response,e) + if e.respond_to?(:response) && e.response.respond_to?(:body) + begin + json_response = MultiJson.load(e.response.body) + extract_response_from_json(json_response, e) + rescue + {} + end else error "ERROR: #{e}" end end - def extract_response_from_json(error_json,e) + def extract_response_from_json(error_json, e) json_error = error_json['errors'] || error_json['error'] if json_error && !json_error.empty? error_string = Array(json_error).join(" ") error "ERROR: #{error_string}" else