Module: OpenToxError
- Included in:
- OpenTox::Error, RuntimeError
- Defined in:
- lib/error.rb
Instance Attribute Summary collapse
-
#cause ⇒ Object
Returns the value of attribute cause.
-
#http_code ⇒ Object
Returns the value of attribute http_code.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
Instance Attribute Details
#cause ⇒ Object
Returns the value of attribute cause.
2 3 4 |
# File 'lib/error.rb', line 2 def cause @cause end |
#http_code ⇒ Object
Returns the value of attribute http_code.
2 3 4 |
# File 'lib/error.rb', line 2 def http_code @http_code end |
#message ⇒ Object
Returns the value of attribute message.
2 3 4 |
# File 'lib/error.rb', line 2 def @message end |
Instance Method Details
#cut_backtrace(trace) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/error.rb', line 16 def cut_backtrace(trace) if trace.is_a?(Array) cut_index = trace.find_index{|line| line.match(/sinatra|minitest/)} cut_index ||= trace.size cut_index -= 1 cut_index = trace.size-1 if cut_index < 0 trace[0..cut_index] else trace end end |
#initialize(message = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/error.rb', line 3 def initialize =nil = .to_s.gsub(/\A"|"\Z/, '') if # remove quotes super @http_code ||= 500 @message = .to_s @cause = cut_backtrace(caller) $logger.error("\n"+JSON.pretty_generate({ :http_code => @http_code, :message => @message, :cause => @cause })) end |