Added new exception page (#466)

This commit is contained in:
Anton Maminov 2018-07-01 16:43:04 +03:00 committed by Serdar Dogruyol
parent d0b4c0d609
commit a13fe95201
4 changed files with 48 additions and 26 deletions

View file

@ -8,6 +8,9 @@ dependencies:
kilt:
github: jeromegn/kilt
version: ~> 0.4.0
exception_page:
github: crystal-loot/exception_page
version: ~> 0.1.1
targets:
kemal:

View file

@ -14,7 +14,7 @@ module Kemal
log("Exception: #{ex.inspect_with_backtrace}")
return call_exception_with_status_code(context, ex, 500) if Kemal.config.error_handlers.has_key?(500)
verbosity = Kemal.config.env == "production" ? false : true
return render_500(context, ex.inspect_with_backtrace, verbosity)
return render_500(context, ex, verbosity)
end
private def call_exception_with_status_code(context : HTTP::Server::Context, exception : Exception, status_code : Int32)

File diff suppressed because one or more lines are too long

View file

@ -21,32 +21,13 @@ def render_404
HTML
end
def render_500(context, backtrace, verbosity)
message = if verbosity
"<pre>#{HTML.escape(backtrace)}</pre>"
else
"<p>Something wrong with the server :(</p>"
end
def render_500(context, exception, verbosity)
template = if verbosity
Kemal::ExceptionPage.for_runtime_exception(context, exception).to_s
else
Kemal::ExceptionPage.for_production_exception
end
template = <<-HTML
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
pre {text-align:left;font-size:14px;color:#fff;background-color:#222;
font-family:Operator,"Source Code Pro",Menlo,Monaco,Inconsolata,monospace;
line-height:1.5;padding:10px;border-radius:2px;overflow:scroll}
</style>
</head>
<body>
<h2>Kemal has encountered an error. (500)</h2>
#{message}
</body>
</html>
HTML
context.response.status_code = 500
context.response.print template
context