[Groonga-commit] ranguba/groonga-client-rails at f9dbeb1 [master] Raise error for error response

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Mar 28 00:22:59 JST 2016


Kouhei Sutou	2016-03-28 00:22:59 +0900 (Mon, 28 Mar 2016)

  New Revision: f9dbeb16a2b4e4190034546e9301c9016c0ee388
  https://github.com/ranguba/groonga-client-rails/commit/f9dbeb16a2b4e4190034546e9301c9016c0ee388

  Message:
    Raise error for error response

  Added files:
    lib/groonga/client/searcher/error.rb
  Modified files:
    lib/groonga/client/searcher.rb
    lib/groonga/client/searcher/raw_request.rb

  Modified: lib/groonga/client/searcher.rb (+1 -0)
===================================================================
--- lib/groonga/client/searcher.rb    2016-03-28 00:15:20 +0900 (641c60b)
+++ lib/groonga/client/searcher.rb    2016-03-28 00:22:59 +0900 (23c81e8)
@@ -16,6 +16,7 @@
 
 require "groonga/client"
 
+require "groonga/client/searcher/error"
 require "groonga/client/searcher/select"
 require "groonga/client/searcher/schema"
 require "groonga/client/searcher/schema_synchronizer"

  Added: lib/groonga/client/searcher/error.rb (+37 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/client/searcher/error.rb    2016-03-28 00:22:59 +0900 (0649142)
@@ -0,0 +1,37 @@
+# Copyright (C) 2016  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+module Groonga
+  class Client
+    class Searcher
+      class Error < Client::Error
+      end
+
+      class ErrorResponse < Error
+        attr_reader :response
+        def initialize(response)
+          @response = response
+          command =****@respo*****
+          status_code =****@respo*****_code
+          error_message =****@respo*****_message
+          message = "failed to execute: #{command.name}: #{status_code}: "
+          message << "<#{error_message}>"
+          super(message)
+        end
+      end
+    end
+  end
+end

  Modified: lib/groonga/client/searcher/raw_request.rb (+3 -1)
===================================================================
--- lib/groonga/client/searcher/raw_request.rb    2016-03-28 00:15:20 +0900 (6ba1db9)
+++ lib/groonga/client/searcher/raw_request.rb    2016-03-28 00:22:59 +0900 (3543207)
@@ -25,7 +25,9 @@ module Groonga
 
         def response
           @reponse ||= Client.open do |client|
-            client.execute(@command_name, to_parameters)
+            response = client.execute(@command_name, to_parameters)
+            raise ErrorResponse.new(response) unless response.success?
+            response
           end
         end
 
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index