Class: Waw::ErrorHandler::Backtrace

Inherits:
Object
  • Object
show all
Defined in:
lib/waw/controllers/error/backtrace.rb

Instance Method Summary collapse

Instance Method Details

#call(kernel, ex) ⇒ Object

Shows a page with a friendly presented backtrace for the error that occured



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/waw/controllers/error/backtrace.rb', line 40

def call(kernel, ex)
  backtrace = case ex
    when ::WLang::Error
      ex.wlang_backtrace
    when ::Exception
      ex.backtrace
    else 
      []
  end
  [500, {'Content-Type' => 'text/html'}, ex_to_html(ex, backtrace)]
end

#ex_backtrace_to_html(backtrace) ⇒ Object

Converts a back-trace to a friendly HTML chunck



7
8
9
# File 'lib/waw/controllers/error/backtrace.rb', line 7

def ex_backtrace_to_html(backtrace)
  "<div>" + backtrace.collect{|s| CGI.escapeHTML(s)}.join('</div><div>') + "</div>"
end

#ex_to_html(ex, backtrace) ⇒ Object

Converts an exception to a friendly HTML chunck



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/waw/controllers/error/backtrace.rb', line 12

def ex_to_html(ex, backtrace)
  "    <html>\n      <head>\n        <style type=\"text/css\">\n          body {\n            font-size: 14px;\n            font-family: \"Courier\", \"Arial\", sans-serif;\n          }\n          p.message {\n            font-size: 16px;\n            font-weight: bold;\n          }\n        </style>\n      </head>\n      <body>\n        <h1>Internal server error (ruby exception)</h1>\n        <p class=\"message\"><code>\#{CGI.escapeHTML(ex.message)}</code></p>\n        <div style=\"margin-left:50px;\">\n          \#{ex_backtrace_to_html(backtrace)}\n        </div>\n      </body>\n    </html>\n  EOF\nend\n"