From ef060311b5d5ebd6ff7ab053871a5ca13afb49f1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 3 Feb 2014 19:26:22 +0100 Subject: [PATCH] Improved error handling. --- lib/search_index_backend.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 74bc5c623..e0320fdb8 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -51,12 +51,10 @@ create/update/delete index req.headers['Content-Type'] = 'application/json' req.body = data[:data].to_json end -# puts response.body.to_s puts "# #{response.status.to_s}" return true if response.success? data = JSON.parse( response.body ) raise data.inspect - #return { :data => data, :response => response } end =begin @@ -80,11 +78,10 @@ add new object to search index req.headers['Content-Type'] = 'application/json' req.body = data.to_json end -# puts response.body.to_s puts "# #{response.status.to_s}" return true if response.success? data = JSON.parse( response.body ) - return { :data => data, :response => response } + raise data.inspect end =begin @@ -105,10 +102,10 @@ remove whole data from index conn = connection( url ) response = conn.delete( url ) -# puts response.body.to_s puts "# #{response.status.to_s}" - return true if response.success? + return false if !response.success? data = JSON.parse( response.body ) +# raise data.inspect return { :data => data, :response => response } end @@ -166,12 +163,12 @@ return search result req.headers['Content-Type'] = 'application/json' req.body = data.to_json end -# puts response.body.to_s puts "# #{response.status.to_s}" - puts response.body -# return true if response.success? data = JSON.parse( response.body ) -# return { :data => data, :response => response } + if !response.success? + raise data.inspect + end + ids = [] return ids if !data return ids if !data['hits'] @@ -180,7 +177,7 @@ return search result puts "... #{item['_type'].to_s} #{item['_id'].to_s}" ids.push item['_id'] } - return ids + ids end =begin