Exception: HTTPStatus::Base

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

Overview

The Base HTTP status exception class is used as superclass for every exception class that is constructed. It implements some shared functionality for finding the status code and determining the template path to render.

Subclasses of this class will be generated on demand when a non-exisiting constant of the HTTPStatus module is requested. This is implemented in the HTTPStatus.const_missing method.

Constant Summary collapse

@@template_path =
'shared/http_status'
@@template_layout =

Use the standard layout template setting by default.

nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes the exception instance.

message

The exception message.

details

An object with details about the exception.



47
48
49
50
# File 'lib/http_status_exceptions.rb', line 47

def initialize(message = nil, details = nil)
  @details = details
  super(message)
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



42
43
44
# File 'lib/http_status_exceptions.rb', line 42

def details
  @details
end

Class Method Details

.statusObject

Returns the HTTP status symbol corresponding to this class. This is one of the symbols that can be found in the map that can be found in ActionController::StatusCodes.

This method should be overridden by subclasses, as it returns :internal_server_error by default. This is done automatically when a new exception class is being generated by HTTPStatus.const_missing.



60
61
62
# File 'lib/http_status_exceptions.rb', line 60

def self.status
  :internal_server_error
end

.status_codeObject

The numeric status code corresponding to this exception class. Uses the status symbol to code map in ActionController::StatusCodes.



72
73
74
# File 'lib/http_status_exceptions.rb', line 72

def self.status_code
  ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[self.status]
end

.templateObject

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



84
85
86
# File 'lib/http_status_exceptions.rb', line 84

def self.template
  "#{template_path}/#{status}"
end

Instance Method Details

#statusObject

Returns the HTTP status symbol (as defined by Rails) corresponding to this instance. By default, it calls the class method of the same name.



66
67
68
# File 'lib/http_status_exceptions.rb', line 66

def status
  self.class.status
end

#status_codeObject

The numeric status code corresponding to this exception. By default, it calls the class method of the same name.



78
79
80
# File 'lib/http_status_exceptions.rb', line 78

def status_code
  self.class.status_code
end

#templateObject

The name of the template that should be used as error page for this exception. By default, it calls the class method of the same name.



90
91
92
# File 'lib/http_status_exceptions.rb', line 90

def template
  self.class.template
end