diff --git a/src/kemal/common_exception_handler.cr b/src/kemal/common_exception_handler.cr index 0fc9575..6321f38 100644 --- a/src/kemal/common_exception_handler.cr +++ b/src/kemal/common_exception_handler.cr @@ -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 diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 1531019..a6d7088 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -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" diff --git a/src/kemal/route_handler.cr b/src/kemal/route_handler.cr index 995ea6f..1f3ad65 100644 --- a/src/kemal/route_handler.cr +++ b/src/kemal/route_handler.cr @@ -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