[Groonga-commit] droonga/fluent-plugin-droonga at 8287858 [master] Detect missing "type"

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Dec 26 14:29:30 JST 2013


YUKI Hiroshi	2013-12-26 14:29:30 +0900 (Thu, 26 Dec 2013)

  New Revision: 82878580a5609ad92567b0718e227db78a219309
  https://github.com/droonga/fluent-plugin-droonga/commit/82878580a5609ad92567b0718e227db78a219309

  Message:
    Detect missing "type"

  Modified files:
    lib/droonga/dispatcher.rb

  Modified: lib/droonga/dispatcher.rb (+17 -11)
===================================================================
--- lib/droonga/dispatcher.rb    2013-12-26 14:20:58 +0900 (9c6bf95)
+++ lib/droonga/dispatcher.rb    2013-12-26 14:29:30 +0900 (0c1bc75)
@@ -35,6 +35,12 @@ module Droonga
     class InvalidRequest < ResponsibleClientError
     end
 
+    class MissingType < InvalidRequest
+      def initialize
+        super("\"type\" must be specified.")
+      end
+    end
+
     class MissingDataset < InvalidRequest
       def initialize
         super("\"dataset\" must be specified.")
@@ -83,8 +89,14 @@ module Droonga
       if message["type"] == "dispatcher"
         process_internal_message(message["body"])
       else
-        return unless assert_have_dataset
-        process_input_message(message)
+        begin
+          assert_valid_message
+          process_input_message(message)
+        rescue ResponsibleError => error
+          response = @output_adapter.adapt(@message.merge("statusCode" => error.status_code,
+                                                          "body" => error.response_body))
+          @replier.reply(response)
+        end
       end
     end
 
@@ -191,15 +203,9 @@ module Droonga
       @distributor.process(adapted_message["type"], adapted_message)
     end
 
-    def assert_have_dataset
-      unles****@messa*****?("dataset")
-        error = MissingDataset.new
-        response = @output_adapter.adapt(@message.merge("statusCode" => error.status_code,
-                                                        "body" => error.response_body))
-        @replier.reply(response)
-        return false
-      end
-      true
+    def assert_valid_message
+      raise MissingType.new unles****@messa*****?("type")
+      raise MissingDataset.new unles****@messa*****?("dataset")
     end
 
     def log_tag
-------------- next part --------------
HTML����������������������������...
Download 



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