Exception: HTTPStatus::Base

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

Constant Summary collapse

@@template_path =
'shared/http_status'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, details = nil) ⇒ Base

Creates the exception with a message and some optional other info.



12
13
14
15
16
# File 'lib/http_status_exceptions.rb', line 12

def initialize(message = nil, details = nil)
  @status = self.class.to_s.split("::").last.underscore.to_sym rescue :internal_server_error
  @details = details
  super(message)
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



9
10
11
# File 'lib/http_status_exceptions.rb', line 9

def details
  @details
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/http_status_exceptions.rb', line 9

def status
  @status
end

Instance Method Details

#status_codeObject

The numeric status code corresponding to this exception



19
20
21
# File 'lib/http_status_exceptions.rb', line 19

def status_code
  ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[@status]
end

#templateObject

The name of the template that should be used as error page for this exception



24
25
26
# File 'lib/http_status_exceptions.rb', line 24

def template
  "#{@@template_path}/#{@status}"
end