mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Make 'additional_fields' optional in JSON error template functions
This allows us to de-duplicate functions
This commit is contained in:
parent
c7b74aa8b4
commit
2d949834e9
1 changed files with 12 additions and 10 deletions
|
@ -129,7 +129,12 @@ macro error_json(*args)
|
||||||
error_json_helper(env, {{*args}})
|
error_json_helper(env, {{*args}})
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_json_helper(env : HTTP::Server::Context, status_code : Int32, exception : Exception, additional_fields : Hash(String, Object) | Nil)
|
def error_json_helper(
|
||||||
|
env : HTTP::Server::Context,
|
||||||
|
status_code : Int32,
|
||||||
|
exception : Exception,
|
||||||
|
additional_fields : Hash(String, Object) | Nil = nil
|
||||||
|
)
|
||||||
if exception.is_a?(InfoException)
|
if exception.is_a?(InfoException)
|
||||||
return error_json_helper(env, status_code, exception.message || "", additional_fields)
|
return error_json_helper(env, status_code, exception.message || "", additional_fields)
|
||||||
end
|
end
|
||||||
|
@ -146,11 +151,12 @@ def error_json_helper(env : HTTP::Server::Context, status_code : Int32, exceptio
|
||||||
return error_message.to_json
|
return error_message.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_json_helper(env : HTTP::Server::Context, status_code : Int32, exception : Exception)
|
def error_json_helper(
|
||||||
return error_json_helper(env, status_code, exception, nil)
|
env : HTTP::Server::Context,
|
||||||
end
|
status_code : Int32,
|
||||||
|
message : String,
|
||||||
def error_json_helper(env : HTTP::Server::Context, status_code : Int32, message : String, additional_fields : Hash(String, Object) | Nil)
|
additional_fields : Hash(String, Object) | Nil = 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
|
||||||
|
|
||||||
|
@ -163,10 +169,6 @@ def error_json_helper(env : HTTP::Server::Context, status_code : Int32, message
|
||||||
return error_message.to_json
|
return error_message.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_json_helper(env : HTTP::Server::Context, status_code : Int32, message : String)
|
|
||||||
error_json_helper(env, status_code, message, nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
# -------------------
|
# -------------------
|
||||||
# Redirect
|
# Redirect
|
||||||
# -------------------
|
# -------------------
|
||||||
|
|
Loading…
Reference in a new issue