From 04ccb973a91da71881ef5d7ef6152b1496d79a6a Mon Sep 17 00:00:00 2001 From: Joris Moriau Date: Thu, 3 Mar 2016 17:14:10 +0100 Subject: [PATCH] set positions for errors and logger middleware, added 2 views --- src/kemal/config.cr | 7 +++---- src/kemal/view.cr | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 1510ec5..5ce26b0 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -49,22 +49,21 @@ module Kemal def setup_logging if @logging @logger ||= Kemal::CommonLogHandler.new(@env) - HANDLERS << @logger.not_nil! + HANDLERS.insert(0, @logger.not_nil!) else @logger = Kemal::NullLogHandler.new(@env) - HANDLERS << @logger.not_nil! end end private def setup_error_handler if @always_rescue @error_handler ||= Kemal::CommonErrorHandler::INSTANCE - HANDLERS << @error_handler.not_nil! + HANDLERS.insert(1, @error_handler.not_nil!) end end private def setup_public_folder - HANDLERS << Kemal::StaticFileHandler.new(@public_folder) if @serve_static + HANDLERS.insert(2, Kemal::StaticFileHandler.new(@public_folder)) if @serve_static end end diff --git a/src/kemal/view.cr b/src/kemal/view.cr index c1cb244..47d6cfa 100644 --- a/src/kemal/view.cr +++ b/src/kemal/view.cr @@ -67,3 +67,51 @@ def render_500(context, ex) context.response.print template context end + +# Template for 415 Unsupported media type +def render_415(context, message) + template = <<-HTML + + + + + + +

Unsupported media type

+

#{message}

+ + + + HTML + context.response.status_code = 415 + context.response.print template + context +end + +# Template for 400 Bad request +def render_400(context, message) + template = <<-HTML + + + + + + +

Bad request

+

#{message}

+ + + + HTML + context.response.status_code = 400 + context.response.print template + context +end