Don't write to context in case of an exception
This commit is contained in:
parent
6611b976a9
commit
76b5add665
3 changed files with 5 additions and 6 deletions
|
@ -10,8 +10,6 @@ module Kemal
|
|||
rescue Kemal::Exceptions::CustomException
|
||||
status_code = context.response.status_code
|
||||
if Kemal.config.error_handlers.has_key?(status_code)
|
||||
context.response.reset
|
||||
context.response.content_type = "text/html"
|
||||
context.response.print Kemal.config.error_handlers[status_code].call(context)
|
||||
return context
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Kemal
|
|||
@server : HTTP::Server?
|
||||
|
||||
property host_binding, ssl, port, env, public_folder, logging,
|
||||
always_rescue, serve_static, server, error_handler
|
||||
always_rescue, serve_static, server
|
||||
|
||||
def initialize
|
||||
@host_binding = "0.0.0.0"
|
||||
|
|
|
@ -31,12 +31,13 @@ class Kemal::RouteHandler < HTTP::Handler
|
|||
|
||||
# Processes the route if it's a match. Otherwise renders 404.
|
||||
def process_request(context)
|
||||
return raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_defined?
|
||||
raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_defined?
|
||||
route = context.route_lookup.payload as Route
|
||||
context.response.print(route.handler.call(context))
|
||||
content = route.handler.call(context)
|
||||
if Kemal.config.error_handlers.has_key?(context.response.status_code)
|
||||
return raise Kemal::Exceptions::CustomException.new(context)
|
||||
raise Kemal::Exceptions::CustomException.new(context)
|
||||
end
|
||||
context.response.print(content)
|
||||
context
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue