diff --git a/lib/neography/connection.rb b/lib/neography/connection.rb index 7d18ed8..dcc71b8 100644 --- a/lib/neography/connection.rb +++ b/lib/neography/connection.rb @@ -48,10 +48,18 @@ def post(path, options={}) def post_chunked(path, options={}) authenticate(configuration + path) result = "" + response = @client.post(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]) do |chunk| result << chunk end - evaluate_chunk_response(response, result) + + r = evaluate_chunk_response(response, result) + + if r.last["status"] > 399 + handle_4xx_500_response(r.last["status"], r.last["body"] || r.last ) + end + + r end def put(path, options={}) @@ -142,6 +150,10 @@ def handle_4xx_500_response(code, body) parsed_body = {} message = "No error message returned from server." stacktrace = "" + elsif body.is_a? Hash + parsed_body = body + message = parsed_body["message"] + stacktrace = parsed_body["stacktrace"] else parsed_body = @parser.json(body) message = parsed_body["message"] diff --git a/spec/integration/rest_batch_spec.rb b/spec/integration/rest_batch_spec.rb index 907a3bd..eef312e 100644 --- a/spec/integration/rest_batch_spec.rb +++ b/spec/integration/rest_batch_spec.rb @@ -441,7 +441,6 @@ [:create_relationship, "has", "{0}", "{2}", {}] batch_result.should_not be_nil - batch_result = @neo.batch [:create_unique_node, "person", "ssn", "000-00-0001", {:first_name=>"Jane", :last_name=>"Doe", :ssn=>"000-00-0001", :_type=>"Person", :created_at=>1335269478}], [:add_node_to_index, "person_ssn", "ssn", "000-00-0001", "{0}"], [:create_node, {:street1=>"94437 Kemmer Crossing", :street2=>"Apt. 333", :city=>"Abshireton", :state=>"AA", :zip=>"65820", :_type=>"Address", :created_at=>1335269478}], @@ -457,22 +456,26 @@ it "should return errors when bad syntax is passed in batch" do batch_commands = [] - batch_commands << [ :create_unique_node, "person", "ssn", "000-00-0001", {:foo => "bar"} ] + # batch_commands << [ :create_unique_node, "person", "ssn", "000-00-0002", {:foo => "bar"} ] # this doesn't raise error - batch_commands << [ :execute_query, "start person_n=node:person(ssn = '000-00-0001') - set bar = {foo}", + batch_commands << [ :execute_query, "start person_n=node:person(ssn = '000-00-0002') + set bar1 = {foo}", { :other => "what" } ] + # this does raise error expect { @neo.execute_query("start person_n=node:person(ssn = '000-00-0001') set bar = {foo}", { :other => "what" }) }.to raise_exception Neography::SyntaxException - - batch_result = @neo.batch *batch_commands + + expect { + batch_result = @neo.batch *batch_commands + }.to raise_exception Neography::SyntaxException + end end