From cd9f3d8f770ba31a04514e126d90257d0030e92d Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Mon, 28 Sep 2020 21:10:41 +0200 Subject: [PATCH] cleanup --- Project.toml | 2 +- src/Router.jl | 15 ++++++++++++--- src/cache_adapters/FileCache.jl | 1 - src/renderers/Html.jl | 2 -- src/renderers/Js.jl | 1 - src/renderers/Json.jl | 1 - 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 4d8951bc3..f0400ddb9 100644 --- a/Project.toml +++ b/Project.toml @@ -43,7 +43,7 @@ Millboard = "0.2" Nettle = "0.5" OrderedCollections = "1" Reexport = "0.2" -Revise = "3.1" +Revise = "2, 3.1" URIParser = "0.4" YAML = "0.4" julia = "1.3" diff --git a/src/Router.jl b/src/Router.jl index e8f90ae51..4b9ce77a0 100755 --- a/src/Router.jl +++ b/src/Router.jl @@ -1054,18 +1054,27 @@ Not implemented function for error response. function error end +function trymime(mime::Any) + try + mime() + catch _ + mime + end +end + + function error(error_message::String, mime::Any, ::Val{500}; error_info::String = "") :: HTTP.Response - HTTP.Response(500, ["Content-Type" => string(mime())], body = "500 Internal Error - $error_message. $error_info") + HTTP.Response(500, ["Content-Type" => string(trymime(mime))], body = "500 Internal Error - $error_message. $error_info") end function error(error_message::String, mime::Any, ::Val{404}; error_info::String = "") :: HTTP.Response - HTTP.Response(404, ["Content-Type" => string(mime())], body = "404 Not Found - $error_message. $error_info") + HTTP.Response(404, ["Content-Type" => string(trymime(mime))], body = "404 Not Found - $error_message. $error_info") end function error(error_code::Int, error_message::String, mime::Any; error_info::String = "") :: HTTP.Response - HTTP.Response(error_code, ["Content-Type" => string(mime())], body = "$error_code Error - $error_message. $error_info") + HTTP.Response(error_code, ["Content-Type" => string(trymime(mime))], body = "$error_code Error - $error_message. $error_info") end diff --git a/src/cache_adapters/FileCache.jl b/src/cache_adapters/FileCache.jl index ce7ac0f08..61ea44691 100755 --- a/src/cache_adapters/FileCache.jl +++ b/src/cache_adapters/FileCache.jl @@ -1,6 +1,5 @@ module FileCache -import Revise import Serialization import Genie, Genie.Cache diff --git a/src/renderers/Html.jl b/src/renderers/Html.jl index 591c38684..db72052e3 100644 --- a/src/renderers/Html.jl +++ b/src/renderers/Html.jl @@ -1,7 +1,5 @@ module Html - -using Revise import Markdown, Logging, Gumbo, Reexport, OrderedCollections, Millboard, HTTP, YAML Reexport.@reexport using Genie diff --git a/src/renderers/Js.jl b/src/renderers/Js.jl index 709480cb2..1ca64174c 100644 --- a/src/renderers/Js.jl +++ b/src/renderers/Js.jl @@ -1,6 +1,5 @@ module Js -import Revise import Logging, HTTP using Genie, Genie.Renderer diff --git a/src/renderers/Json.jl b/src/renderers/Json.jl index ba135682d..00d52f5ce 100644 --- a/src/renderers/Json.jl +++ b/src/renderers/Json.jl @@ -1,6 +1,5 @@ module Json -import Revise import JSON, HTTP using Genie, Genie.Renderer