kemal/src/kemal/common_exception_handler.cr

19 lines
629 B
Crystal
Raw Normal View History

class Kemal::CommonExceptionHandler < HTTP::Handler
2016-02-14 10:43:25 +00:00
INSTANCE = new
def call(context)
begin
call_next context
rescue ex : Kemal::Exceptions::RouteNotFound
context.response.content_type = "text/html"
Kemal.config.logger.write("Exception: #{ex.inspect_with_backtrace}\n")
2016-02-14 10:43:25 +00:00
return render_404(context)
rescue ex
context.response.content_type = "text/html"
Kemal.config.logger.write("Exception: #{ex.inspect_with_backtrace}\n")
verbosity = Kemal.config.env == "production" ? false : true
return render_500(context, ex.inspect_with_backtrace, verbosity)
2016-02-14 10:43:25 +00:00
end
end
end