|
|
@ -7,7 +7,7 @@ class InfoException < Exception
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
macro error_template(*args)
|
|
|
|
macro error_template(*args)
|
|
|
|
error_template_helper(env, config, locale, {{*args}})
|
|
|
|
error_template_helper(env, locale, {{*args}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def github_details(summary : String, content : String)
|
|
|
|
def github_details(summary : String, content : String)
|
|
|
@ -22,9 +22,9 @@ def github_details(summary : String, content : String)
|
|
|
|
return HTML.escape(details)
|
|
|
|
return HTML.escape(details)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def error_template_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
|
|
|
def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
|
|
|
if exception.is_a?(InfoException)
|
|
|
|
if exception.is_a?(InfoException)
|
|
|
|
return error_template_helper(env, config, locale, status_code, exception.message || "")
|
|
|
|
return error_template_helper(env, locale, status_code, exception.message || "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
env.response.content_type = "text/html"
|
|
|
|
env.response.content_type = "text/html"
|
|
|
|
env.response.status_code = status_code
|
|
|
|
env.response.status_code = status_code
|
|
|
@ -43,7 +43,7 @@ def error_template_helper(env : HTTP::Server::Context, config : Config, locale :
|
|
|
|
return templated "error"
|
|
|
|
return templated "error"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def error_template_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
|
|
|
def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
|
|
|
env.response.content_type = "text/html"
|
|
|
|
env.response.content_type = "text/html"
|
|
|
|
env.response.status_code = status_code
|
|
|
|
env.response.status_code = status_code
|
|
|
|
error_message = translate(locale, message)
|
|
|
|
error_message = translate(locale, message)
|
|
|
@ -51,31 +51,31 @@ def error_template_helper(env : HTTP::Server::Context, config : Config, locale :
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
macro error_atom(*args)
|
|
|
|
macro error_atom(*args)
|
|
|
|
error_atom_helper(env, config, locale, {{*args}})
|
|
|
|
error_atom_helper(env, locale, {{*args}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def error_atom_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
|
|
|
def error_atom_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
|
|
|
if exception.is_a?(InfoException)
|
|
|
|
if exception.is_a?(InfoException)
|
|
|
|
return error_atom_helper(env, config, locale, status_code, exception.message || "")
|
|
|
|
return error_atom_helper(env, locale, status_code, exception.message || "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
env.response.content_type = "application/atom+xml"
|
|
|
|
env.response.content_type = "application/atom+xml"
|
|
|
|
env.response.status_code = status_code
|
|
|
|
env.response.status_code = status_code
|
|
|
|
return "<error>#{exception.inspect_with_backtrace}</error>"
|
|
|
|
return "<error>#{exception.inspect_with_backtrace}</error>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def error_atom_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
|
|
|
def error_atom_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
|
|
|
env.response.content_type = "application/atom+xml"
|
|
|
|
env.response.content_type = "application/atom+xml"
|
|
|
|
env.response.status_code = status_code
|
|
|
|
env.response.status_code = status_code
|
|
|
|
return "<error>#{message}</error>"
|
|
|
|
return "<error>#{message}</error>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
macro error_json(*args)
|
|
|
|
macro error_json(*args)
|
|
|
|
error_json_helper(env, config, locale, {{*args}})
|
|
|
|
error_json_helper(env, locale, {{*args}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def error_json_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception, additional_fields : Hash(String, Object) | Nil)
|
|
|
|
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception, additional_fields : Hash(String, Object) | Nil)
|
|
|
|
if exception.is_a?(InfoException)
|
|
|
|
if exception.is_a?(InfoException)
|
|
|
|
return error_json_helper(env, config, locale, status_code, exception.message || "", additional_fields)
|
|
|
|
return error_json_helper(env, locale, status_code, exception.message || "", additional_fields)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
env.response.status_code = status_code
|
|
|
|
env.response.status_code = status_code
|
|
|
@ -86,11 +86,11 @@ def error_json_helper(env : HTTP::Server::Context, config : Config, locale : Has
|
|
|
|
return error_message.to_json
|
|
|
|
return error_message.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def error_json_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
|
|
|
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
|
|
|
return error_json_helper(env, config, locale, status_code, exception, nil)
|
|
|
|
return error_json_helper(env, locale, status_code, exception, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def error_json_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String, additional_fields : Hash(String, Object) | Nil)
|
|
|
|
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String, additional_fields : Hash(String, Object) | Nil)
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
env.response.status_code = status_code
|
|
|
|
env.response.status_code = status_code
|
|
|
|
error_message = {"error" => message}
|
|
|
|
error_message = {"error" => message}
|
|
|
@ -100,6 +100,6 @@ def error_json_helper(env : HTTP::Server::Context, config : Config, locale : Has
|
|
|
|
return error_message.to_json
|
|
|
|
return error_message.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def error_json_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
|
|
|
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
|
|
|
error_json_helper(env, config, locale, status_code, message, nil)
|
|
|
|
error_json_helper(env, locale, status_code, message, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|