Exception: Wrangler::HttpStatusError

Inherits:
Exception
  • Object
show all
Defined in:
lib/wrangler/wrangler_exceptions.rb

Overview

base class for all the http-related exception classes


Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, addl_msg = nil) ⇒ HttpStatusError

Returns a new instance of HttpStatusError.



7
8
9
10
11
12
13
14
15
# File 'lib/wrangler/wrangler_exceptions.rb', line 7

def initialize(status_code, addl_msg = nil)
  @status_code = status_code
  @addl_msg = addl_msg

  full_message = self.class.status_to_msg(status_code)
  full_message += addl_msg unless addl_msg.nil?

  super(full_message)
end

Instance Attribute Details

#addl_msgObject (readonly)

Returns the value of attribute addl_msg.



17
18
19
# File 'lib/wrangler/wrangler_exceptions.rb', line 17

def addl_msg
  @addl_msg
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



17
18
19
# File 'lib/wrangler/wrangler_exceptions.rb', line 17

def status_code
  @status_code
end

Class Method Details

.status_to_msg(status) ⇒ Object

accepts either a Fixnum status code or a symbol representation of a status code (e.g. 404 or :not_found) yes, this is total duplication of code in action_controller/status_codes.rb, but it’s been made a private instance method in the module.




25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wrangler/wrangler_exceptions.rb', line 25

def self.status_to_msg(status)
  case status
  when Fixnum then
    "#{status} #{ActionController::StatusCodes::STATUS_CODES[status]}".strip
  when Symbol then
    status_to_msg(ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[status] ||
      "500 Unknown Status #{status.inspect}")
  else
    status.to_s
  end
end