From 5daba08ce46d22dff7e635763c6fce6431755524 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Tue, 19 May 2015 18:57:52 +0200 Subject: [PATCH] [API] Changed more APIs to use the unified `NotFound` error handling Related: 4e2a3d3 Related: #126 --- elasticsearch-api/lib/elasticsearch/api/actions/delete.rb | 8 ++------ elasticsearch-api/lib/elasticsearch/api/actions/get.rb | 8 ++------ .../lib/elasticsearch/api/actions/get_source.rb | 8 ++------ .../lib/elasticsearch/api/actions/get_template.rb | 7 ++----- .../lib/elasticsearch/api/actions/indices/delete.rb | 8 ++------ .../elasticsearch/api/actions/indices/delete_template.rb | 8 ++------ elasticsearch-api/lib/elasticsearch/api/actions/update.rb | 8 ++------ 7 files changed, 14 insertions(+), 41 deletions(-) diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/delete.rb b/elasticsearch-api/lib/elasticsearch/api/actions/delete.rb index c086ef6615..96b49d651b 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/delete.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/delete.rb @@ -51,12 +51,8 @@ def delete(arguments={}) params = Utils.__validate_and_extract_params arguments, valid_params body = nil - perform_request(method, path, params, body).body - - rescue Exception => e - # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability - if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false - else raise(e) + Utils.__rescue_from_not_found do + perform_request(method, path, params, body).body end end end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/get.rb b/elasticsearch-api/lib/elasticsearch/api/actions/get.rb index 2d9c326f09..b1168d7c14 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/get.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/get.rb @@ -61,12 +61,8 @@ def get(arguments={}) params[:fields] = Utils.__listify(params[:fields]) if params[:fields] - perform_request(method, path, params, body).body - - rescue Exception => e - # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability - if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false - else raise(e) + Utils.__rescue_from_not_found do + perform_request(method, path, params, body).body end end end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/get_source.rb b/elasticsearch-api/lib/elasticsearch/api/actions/get_source.rb index 3332a00fde..d010ade12a 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/get_source.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/get_source.rb @@ -58,12 +58,8 @@ def get_source(arguments={}) params[:fields] = Utils.__listify(params[:fields]) if params[:fields] - perform_request(method, path, params, body).body - - rescue Exception => e - # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability - if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false - else raise(e) + Utils.__rescue_from_not_found do + perform_request(method, path, params, body).body end end end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/get_template.rb b/elasticsearch-api/lib/elasticsearch/api/actions/get_template.rb index 9682bbb787..ff95f6511e 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/get_template.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/get_template.rb @@ -16,11 +16,8 @@ def get_template(arguments={}) params = {} body = arguments[:body] - perform_request(method, path, params, body).body - rescue Exception => e - # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability - if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false - else raise(e) + Utils.__rescue_from_not_found do + perform_request(method, path, params, body).body end end end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/indices/delete.rb b/elasticsearch-api/lib/elasticsearch/api/actions/indices/delete.rb index e2049405a8..41737ebde6 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/indices/delete.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/indices/delete.rb @@ -38,12 +38,8 @@ def delete(arguments={}) params = Utils.__validate_and_extract_params arguments, valid_params body = nil - perform_request(method, path, params, body).body - - rescue Exception => e - # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability - if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false - else raise(e) + Utils.__rescue_from_not_found do + perform_request(method, path, params, body).body end end end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/indices/delete_template.rb b/elasticsearch-api/lib/elasticsearch/api/actions/indices/delete_template.rb index 4e184125c5..15994a5b9e 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/indices/delete_template.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/indices/delete_template.rb @@ -28,12 +28,8 @@ def delete_template(arguments={}) params = Utils.__validate_and_extract_params arguments, valid_params body = nil - perform_request(method, path, params, body).body - - rescue Exception => e - # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability - if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false - else raise(e) + Utils.__rescue_from_not_found do + perform_request(method, path, params, body).body end end end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/update.rb b/elasticsearch-api/lib/elasticsearch/api/actions/update.rb index 3fe49a7487..1038e08c9a 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/update.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/update.rb @@ -94,12 +94,8 @@ def update(arguments={}) params[:fields] = Utils.__listify(params[:fields]) if params[:fields] - perform_request(method, path, params, body).body - - rescue Exception => e - # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability - if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false - else raise(e) + Utils.__rescue_from_not_found do + perform_request(method, path, params, body).body end end end