Navigation Menu

Skip to content

Commit

Permalink
Define error classes under the namespace "Droonga::ErrorMessage"
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Feb 19, 2014
1 parent 8e863cf commit 352e712
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/droonga/catalog/base.rb
Expand Up @@ -16,7 +16,7 @@
require "digest/sha1"
require "zlib"
require "time"
require "droonga/message_processing_error"
require "droonga/error_message"
require "droonga/catalog/errors"

module Droonga
Expand Down
6 changes: 3 additions & 3 deletions lib/droonga/dispatcher.rb
Expand Up @@ -22,7 +22,7 @@
require "droonga/farm"
require "droonga/session"
require "droonga/replier"
require "droonga/message_processing_error"
require "droonga/error_message"
require "droonga/distributor"

module Droonga
Expand Down Expand Up @@ -96,12 +96,12 @@ def process_message(message)
begin
assert_valid_message(message)
process_input_message(message)
rescue MessageProcessingError => error
rescue ErrorMessage::Error => error
reply("statusCode" => error.status_code,
"body" => error.response_body)
rescue StandardError, LoadError, SyntaxError => error
Logger.error("failed to process input message", error)
formatted_error = MessageProcessingError.new("Unknown internal error")
formatted_error = ErrorMessage::InternalServerError.new("Unknown internal error")
reply("statusCode" => formatted_error.status_code,
"body" => formatted_error.response_body)
raise error
Expand Down
2 changes: 1 addition & 1 deletion lib/droonga/distributed_command_planner.rb
Expand Up @@ -127,7 +127,7 @@ def unified_gatherers
def fixed_processor
@processor["outputs"] = @outputs
if @processor["type"] == "scatter"
raise MessageProcessingError.new("missing key") unless @key
raise ErrorMessage::InternalServerError.new("missing key") unless @key
@processor["key"] = @key
end
@processor
Expand Down
Expand Up @@ -17,8 +17,9 @@
require "droonga/status_code"

module Droonga
class MessageProcessingError < Error
STATUS_CODE = StatusCode::INTERNAL_SERVER_ERROR
module ErrorMessage
class Error < Droonga::Error
STATUS_CODE = nil

attr_reader :detail

Expand All @@ -45,11 +46,16 @@ def response_body
end
end

class BadRequest < MessageProcessingError
class InternalServerError < Error
STATUS_CODE = StatusCode::INTERNAL_SERVER_ERROR
end

class BadRequest < Error
STATUS_CODE = StatusCode::BAD_REQUEST
end

class NotFound < MessageProcessingError
class NotFound < Error
STATUS_CODE = StatusCode::NOT_FOUND
end
end
end
2 changes: 1 addition & 1 deletion lib/droonga/handler_runner.rb
Expand Up @@ -96,7 +96,7 @@ def process_command(handler_class, command, raw_message)
handler = handler_class.new(@name, @context)
begin
handler.handle(handler_message, messenger)
rescue MessageProcessingError => error
rescue ErrorMessage::Error => error
messenger.error(error.status_code, error.response_body)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/droonga/plugins/crud.rb
Expand Up @@ -16,7 +16,7 @@
require "groonga"

require "droonga/plugin"
require "droonga/message_processing_error"
require "droonga/error_message"

module Droonga
module Plugins
Expand Down
2 changes: 1 addition & 1 deletion lib/droonga/plugins/error.rb
Expand Up @@ -36,7 +36,7 @@ def adapt_output(output_message)
if status_codes.size == 1
output_message.status_code = status_codes.first
else
output_message.status_code = MessageProcessingError::STATUS_CODE
output_message.status_code = ErrorMessage::InternalServerError::STATUS_CODE
end

output_message.body = errors.values.first["body"]
Expand Down
2 changes: 1 addition & 1 deletion lib/droonga/searcher.rb
Expand Up @@ -20,7 +20,7 @@
require "groonga"

require "droonga/time_formatter"
require "droonga/message_processing_error"
require "droonga/error_message"

module Droonga
class Searcher
Expand Down

0 comments on commit 352e712

Please sign in to comment.