mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Improve common_exception_handler to handler custom 500 errors. Fixes #175.
This commit is contained in:
parent
c718b02dbc
commit
19581d6e3e
2 changed files with 37 additions and 21 deletions
|
@ -7,21 +7,24 @@ module Kemal
|
|||
call_next(context)
|
||||
rescue Kemal::Exceptions::RouteNotFound
|
||||
context.response.content_type = "text/html"
|
||||
context.response.status_code = 404
|
||||
context.response.print Kemal.config.error_handlers[404].call(context)
|
||||
return context
|
||||
call_exception_with_status_code(context, 404)
|
||||
rescue Kemal::Exceptions::CustomException
|
||||
status_code = context.response.status_code
|
||||
if Kemal.config.error_handlers.has_key?(status_code)
|
||||
context.response.print Kemal.config.error_handlers[status_code].call(context)
|
||||
return context
|
||||
end
|
||||
call_exception_with_status_code(context, context.response.status_code)
|
||||
rescue ex : Exception
|
||||
context.response.content_type = "text/html"
|
||||
Kemal.config.logger.write("Exception: #{ex.inspect_with_backtrace}\n")
|
||||
return call_exception_with_status_code(context, 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)
|
||||
end
|
||||
end
|
||||
|
||||
def call_exception_with_status_code(context, status_code)
|
||||
if Kemal.config.error_handlers.has_key?(status_code)
|
||||
context.response.status_code = status_code
|
||||
context.response.print Kemal.config.error_handlers[status_code].call(context)
|
||||
return context
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue