mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-04-11.git
synced 2024-08-15 00:43:26 +00:00
Debloat errors.cr
This commit is contained in:
parent
3fe030bca9
commit
41b7555519
3 changed files with 52 additions and 54 deletions
18
src/invidious/errors/atom.cr
Normal file
18
src/invidious/errors/atom.cr
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
macro error_atom(*args)
|
||||||
|
error_atom_helper(env, locale, {{*args}})
|
||||||
|
end
|
||||||
|
|
||||||
|
def error_atom_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
||||||
|
if exception.is_a?(InfoException)
|
||||||
|
return error_atom_helper(env, locale, status_code, exception.message || "")
|
||||||
|
end
|
||||||
|
env.response.content_type = "application/atom+xml"
|
||||||
|
env.response.status_code = status_code
|
||||||
|
return "<error>#{exception.inspect_with_backtrace}</error>"
|
||||||
|
end
|
||||||
|
|
||||||
|
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.status_code = status_code
|
||||||
|
return "<error>#{message}</error>"
|
||||||
|
end
|
|
@ -46,60 +46,6 @@ def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSO
|
||||||
return templated "error"
|
return templated "error"
|
||||||
end
|
end
|
||||||
|
|
||||||
macro error_atom(*args)
|
|
||||||
error_atom_helper(env, locale, {{*args}})
|
|
||||||
end
|
|
||||||
|
|
||||||
def error_atom_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
|
||||||
if exception.is_a?(InfoException)
|
|
||||||
return error_atom_helper(env, locale, status_code, exception.message || "")
|
|
||||||
end
|
|
||||||
env.response.content_type = "application/atom+xml"
|
|
||||||
env.response.status_code = status_code
|
|
||||||
return "<error>#{exception.inspect_with_backtrace}</error>"
|
|
||||||
end
|
|
||||||
|
|
||||||
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.status_code = status_code
|
|
||||||
return "<error>#{message}</error>"
|
|
||||||
end
|
|
||||||
|
|
||||||
macro error_json(*args)
|
|
||||||
error_json_helper(env, locale, {{*args}})
|
|
||||||
end
|
|
||||||
|
|
||||||
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)
|
|
||||||
return error_json_helper(env, locale, status_code, exception.message || "", additional_fields)
|
|
||||||
end
|
|
||||||
env.response.content_type = "application/json"
|
|
||||||
env.response.status_code = status_code
|
|
||||||
error_message = {"error" => exception.message, "errorBacktrace" => exception.inspect_with_backtrace}
|
|
||||||
if additional_fields
|
|
||||||
error_message = error_message.merge(additional_fields)
|
|
||||||
end
|
|
||||||
return error_message.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
|
||||||
return error_json_helper(env, locale, status_code, exception, nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
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.status_code = status_code
|
|
||||||
error_message = {"error" => message}
|
|
||||||
if additional_fields
|
|
||||||
error_message = error_message.merge(additional_fields)
|
|
||||||
end
|
|
||||||
return error_message.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
|
||||||
error_json_helper(env, locale, status_code, message, nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
def error_redirect_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil)
|
def error_redirect_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil)
|
||||||
request_path = env.request.path
|
request_path = env.request.path
|
||||||
|
|
||||||
|
|
34
src/invidious/errors/json.cr
Normal file
34
src/invidious/errors/json.cr
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
macro error_json(*args)
|
||||||
|
error_json_helper(env, locale, {{*args}})
|
||||||
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
return error_json_helper(env, locale, status_code, exception.message || "", additional_fields)
|
||||||
|
end
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
env.response.status_code = status_code
|
||||||
|
error_message = {"error" => exception.message, "errorBacktrace" => exception.inspect_with_backtrace}
|
||||||
|
if additional_fields
|
||||||
|
error_message = error_message.merge(additional_fields)
|
||||||
|
end
|
||||||
|
return error_message.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
|
||||||
|
return error_json_helper(env, locale, status_code, exception, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
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.status_code = status_code
|
||||||
|
error_message = {"error" => message}
|
||||||
|
if additional_fields
|
||||||
|
error_message = error_message.merge(additional_fields)
|
||||||
|
end
|
||||||
|
return error_message.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
||||||
|
error_json_helper(env, locale, status_code, message, nil)
|
||||||
|
end
|
Loading…
Reference in a new issue