diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2022-01-19 22:15:43 +0100 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2022-01-28 02:19:53 +0100 |
| commit | 2d949834e976d433899341e46c72e7d8514ce50f (patch) | |
| tree | 5a524ee81e6b765235f75c6e669ec2867556cb94 /src | |
| parent | c7b74aa8b415819f44a4c32ee13ba26b9fd594c8 (diff) | |
| download | invidious-2d949834e976d433899341e46c72e7d8514ce50f.tar.gz invidious-2d949834e976d433899341e46c72e7d8514ce50f.tar.bz2 invidious-2d949834e976d433899341e46c72e7d8514ce50f.zip | |
Make 'additional_fields' optional in JSON error template functions
This allows us to de-duplicate functions
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/helpers/errors.cr | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index 1a1366fe..3acbac84 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -129,7 +129,12 @@ macro error_json(*args) error_json_helper(env, {{*args}}) 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) return error_json_helper(env, status_code, exception.message || "", additional_fields) end @@ -146,11 +151,12 @@ def error_json_helper(env : HTTP::Server::Context, status_code : Int32, exceptio return error_message.to_json end -def error_json_helper(env : HTTP::Server::Context, status_code : Int32, exception : Exception) - return error_json_helper(env, status_code, exception, nil) -end - -def error_json_helper(env : HTTP::Server::Context, status_code : Int32, message : String, additional_fields : Hash(String, Object) | Nil) +def error_json_helper( + env : HTTP::Server::Context, + status_code : Int32, + message : String, + additional_fields : Hash(String, Object) | Nil = nil +) env.response.content_type = "application/json" 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 end -def error_json_helper(env : HTTP::Server::Context, status_code : Int32, message : String) - error_json_helper(env, status_code, message, nil) -end - # ------------------- # Redirect # ------------------- |
