Exception: Lux::Error
Overview
default error handler for lux e = Lux::Error.new 404 e.code => 404 e.message => ‘Not Found’
e = Lux::Error.not_found(‘foo’) e.code => 404 e.message => foo
Direct Known Subclasses
Defined Under Namespace
Classes: AutoRaise
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
Class Method Summary collapse
-
.inline(name, error = nil) ⇒ Object
render error inline or break in production.
- .log(error) ⇒ Object
-
.render(text, status = 500) ⇒ Object
template to show full error page.
- .report(code, msg = nil) ⇒ Object
- .split_backtrace(error) ⇒ Object
Instance Method Summary collapse
- #code ⇒ Object
- #code=(num) ⇒ Object
-
#initialize(code_num, message = nil) ⇒ Error
constructor
A new instance of Error.
- #render ⇒ Object
Constructor Details
#initialize(code_num, message = nil) ⇒ Error
Returns a new instance of Error.
173 174 175 176 |
# File 'lib/lux/error/error.rb', line 173 def initialize code_num, =nil self.code = code_num @message = || CODE_LIST[code_num][:name] end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
171 172 173 |
# File 'lib/lux/error/error.rb', line 171 def @message end |
Class Method Details
.inline(name, error = nil) ⇒ Object
render error inline or break in production
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/lux/error/error.rb', line 114 def inline name, error=nil error ||= $! unless Lux.config(:dump_errors) key = log error render "Lux inline error: %s\n\nkey: %s" % [error., key] end name ||= 'Undefined name' msg = error..to_s.gsub('","',%[",\n "]).gsub('<','<') dmp = split_backtrace error dmp[0] = dmp[0].map { |_| _ = _.split(':', 3); '<b>%s</b> - %s - %s' % _ } log error <<~TEXT <pre style="color:red; background:#eee; padding:10px; font-family:'Lucida Console'; line-height:15pt; font-size:11pt;"> <b style="font-size:110%;">#{name}</b> <b>#{error}: #{msg}</b> #{dmp[0].join("\n")} #{dmp[1].join("\n")} </pre> TEXT end |
.log(error) ⇒ Object
150 151 152 |
# File 'lib/lux/error/error.rb', line 150 def log error Lux.config.error_logger.call error end |
.render(text, status = 500) ⇒ Object
template to show full error page
107 108 109 110 111 |
# File 'lib/lux/error/error.rb', line 107 def render text, status=500 Lux.current.response.status status Lux.current.response.body Lux.config.server_error_template.call(text) throw :done end |
.report(code, msg = nil) ⇒ Object
144 145 146 147 148 |
# File 'lib/lux/error/error.rb', line 144 def report code, msg=nil e = Integer === code ? Lux::Error.new(code) : Lux::Error.send(code) e. = msg if msg raise e end |
.split_backtrace(error) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/lux/error/error.rb', line 154 def split_backtrace error # split app log rest of the log dmp = [[], []] root = Lux.root.to_s error.backtrace.each do |line| line = line.sub(root, '.') dmp[line[0,1] == '.' ? 0 : 1].push line end dmp end |
Instance Method Details
#code ⇒ Object
178 179 180 181 |
# File 'lib/lux/error/error.rb', line 178 def code # 400 is a default @code || 400 end |
#code=(num) ⇒ Object
183 184 185 186 187 |
# File 'lib/lux/error/error.rb', line 183 def code= num @code = num.to_i raise 'Status code %s not found' % @code unless CODE_LIST[@code] end |
#render ⇒ Object
189 190 191 |
# File 'lib/lux/error/error.rb', line 189 def render self.class.render , code end |