From 63e613a43905a476497b4bc874208e1e0bd04eb2 Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Thu, 5 Oct 2017 19:52:57 +0300 Subject: [PATCH] Don't try to call error_handlers if there isn't any --- src/kemal/common_exception_handler.cr | 2 +- src/kemal/route_handler.cr | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/kemal/common_exception_handler.cr b/src/kemal/common_exception_handler.cr index 24eccfe..e31c4c9 100644 --- a/src/kemal/common_exception_handler.cr +++ b/src/kemal/common_exception_handler.cr @@ -20,7 +20,7 @@ module Kemal end private def call_exception_with_status_code(context : HTTP::Server::Context, exception : Exception, status_code : Int32) - if Kemal.config.error_handlers.has_key?(status_code) + if Kemal.config.error_handlers.size != 0 && Kemal.config.error_handlers.has_key?(status_code) context.response.content_type = "text/html" unless context.response.headers.has_key?("Content-Type") context.response.print Kemal.config.error_handlers[status_code].call(context, exception) context.response.status_code = status_code diff --git a/src/kemal/route_handler.cr b/src/kemal/route_handler.cr index 60eaf34..7cb3de7 100644 --- a/src/kemal/route_handler.cr +++ b/src/kemal/route_handler.cr @@ -32,10 +32,11 @@ module Kemal private def process_request(context) raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_defined? content = context.route.handler.call(context) - ensure - if Kemal.config.error_handlers.has_key?(context.response.status_code) + + if Kemal.config.error_handlers.size != 0 && Kemal.config.error_handlers.has_key?(context.response.status_code) raise Kemal::Exceptions::CustomException.new(context) end + context.response.print(content) context end