Exception: Rango::Exceptions::HttpError

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

Direct Known Subclasses

Redirection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = self.class.name, status = nil) ⇒ HttpError

raise Redirection.new(“/”, 301)



74
75
76
77
# File 'lib/rango/exceptions.rb', line 74

def initialize(message = self.class.name, status = nil)
  self.status = status unless status.nil?
  self.message = message
end

Instance Attribute Details

#backtraceObject



29
30
31
# File 'lib/rango/exceptions.rb', line 29

def backtrace
  super || @backtrace
end

#messageObject



41
42
43
# File 'lib/rango/exceptions.rb', line 41

def message
  @message ||= self.class.message
end

#statusObject



61
62
63
# File 'lib/rango/exceptions.rb', line 61

def status
  @status ||= self.class.status
end

Class Method Details

.headersObject



65
66
67
# File 'lib/rango/exceptions.rb', line 65

def self.headers
  @headers ||= {"Content-Type" => "text/html"}
end

.messageObject



33
34
35
36
37
38
# File 'lib/rango/exceptions.rb', line 33

def self.message
  @message ||= begin
    self.superclass.message
  rescue NoMethodError
  end
end

.message=(message) ⇒ Object



23
24
25
# File 'lib/rango/exceptions.rb', line 23

def self.message=(message)
  @message = message
end

.nameObject



15
16
17
# File 'lib/rango/exceptions.rb', line 15

def self.name
  @name
end

.name=(name) ⇒ Object



11
12
13
# File 'lib/rango/exceptions.rb', line 11

def self.name=(name)
  @name = name
end

.statusObject



49
50
51
52
53
54
# File 'lib/rango/exceptions.rb', line 49

def self.status
  @status ||= begin
    self.superclass.status
  rescue NoMethodError
  end
end

.status=(status) ⇒ Object



45
46
47
# File 'lib/rango/exceptions.rb', line 45

def self.status=(status)
  @status = status
end

Instance Method Details

#headersObject



69
70
71
# File 'lib/rango/exceptions.rb', line 69

def headers
  @headers ||= self.class.headers.dup
end

#inspectObject



79
80
81
# File 'lib/rango/exceptions.rb', line 79

def inspect
  self.to_response.inspect
end

#nameObject



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

def name
  @name ||= self.class.name
end

#to_responseObject



89
90
91
# File 'lib/rango/exceptions.rb', line 89

def to_response
  [self.status, self.headers, [self.message].compact]
end

#to_snakecaseObject

Examples:

NotFound.new.to_snakecase # “not_found”



85
86
87
# File 'lib/rango/exceptions.rb', line 85

def to_snakecase
  self.class.name.gsub(" ", "_").downcase
end