Skip to content

Commit 2d94983

Browse files
committed
Make 'additional_fields' optional in JSON error template functions
This allows us to de-duplicate functions
1 parent c7b74aa commit 2d94983

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/invidious/helpers/errors.cr

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ macro error_json(*args)
129129
error_json_helper(env, {{*args}})
130130
end
131131

132-
def error_json_helper(env : HTTP::Server::Context, status_code : Int32, exception : Exception, additional_fields : Hash(String, Object) | Nil)
132+
def error_json_helper(
133+
env : HTTP::Server::Context,
134+
status_code : Int32,
135+
exception : Exception,
136+
additional_fields : Hash(String, Object) | Nil = nil
137+
)
133138
if exception.is_a?(InfoException)
134139
return error_json_helper(env, status_code, exception.message || "", additional_fields)
135140
end
@@ -146,11 +151,12 @@ def error_json_helper(env : HTTP::Server::Context, status_code : Int32, exceptio
146151
return error_message.to_json
147152
end
148153

149-
def error_json_helper(env : HTTP::Server::Context, status_code : Int32, exception : Exception)
150-
return error_json_helper(env, status_code, exception, nil)
151-
end
152-
153-
def error_json_helper(env : HTTP::Server::Context, status_code : Int32, message : String, additional_fields : Hash(String, Object) | Nil)
154+
def error_json_helper(
155+
env : HTTP::Server::Context,
156+
status_code : Int32,
157+
message : String,
158+
additional_fields : Hash(String, Object) | Nil = nil
159+
)
154160
env.response.content_type = "application/json"
155161
env.response.status_code = status_code
156162

@@ -163,10 +169,6 @@ def error_json_helper(env : HTTP::Server::Context, status_code : Int32, message
163169
return error_message.to_json
164170
end
165171

166-
def error_json_helper(env : HTTP::Server::Context, status_code : Int32, message : String)
167-
error_json_helper(env, status_code, message, nil)
168-
end
169-
170172
# -------------------
171173
# Redirect
172174
# -------------------

0 commit comments

Comments
 (0)