mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Merge pull request #147 from sdogruyol/error-404-customize
Allow 404 error handler to be customizable
This commit is contained in:
commit
e7ebb7f45d
3 changed files with 9 additions and 8 deletions
|
@ -12,8 +12,10 @@ module Kemal
|
|||
config.server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers)
|
||||
config.server.not_nil!.ssl = config.ssl
|
||||
|
||||
error 404 do |env|
|
||||
render_404(env)
|
||||
unless Kemal.config.error_handlers.has_key?(404)
|
||||
error 404 do |env|
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
# Test environment doesn't need to have signal trap, built-in images, and logging.
|
||||
|
|
|
@ -6,7 +6,10 @@ module Kemal
|
|||
begin
|
||||
call_next(context)
|
||||
rescue Kemal::Exceptions::RouteNotFound
|
||||
return Kemal.config.error_handlers[404].call(context)
|
||||
context.response.content_type = "text/html"
|
||||
context.response.status_code = 404
|
||||
context.response.print Kemal.config.error_handlers[404].call(context)
|
||||
return context
|
||||
rescue Kemal::Exceptions::CustomException
|
||||
status_code = context.response.status_code
|
||||
if Kemal.config.error_handlers.has_key?(status_code)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Template for 404 Not Found
|
||||
def render_404(context)
|
||||
def render_404
|
||||
template = <<-HTML
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
@ -16,10 +16,6 @@ def render_404(context)
|
|||
</body>
|
||||
</html>
|
||||
HTML
|
||||
context.response.content_type = "text/html"
|
||||
context.response.status_code = 404
|
||||
context.response.print template
|
||||
context
|
||||
end
|
||||
|
||||
# Template for 500 Internal Server Error
|
||||
|
|
Loading…
Reference in a new issue