# InfoExceptions are for displaying information to the user. # # An InfoException might or might not indicate that something went wrong. # Historically Invidious didn't differentiate between these two options, so to # maintain previous functionality InfoExceptions do not print backtraces. class InfoException < Exception end macro error_template(*args) error_template_helper(env, config, locale, {{*args}}) end def error_template_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception) if exception.is_a?(InfoException) return error_template_helper(env, config, locale, status_code, exception.message || "") end env.response.status_code = status_code issue_template = %(Date: `#{Time::Format::ISO_8601_DATE_TIME.format(Time.utc)}`) issue_template += %(\nRoute: `#{env.request.resource}`) issue_template += %(\nVersion: `#{SOFTWARE["version"]} @ #{SOFTWARE["branch"]}`) #issue_template += %(\nPreferences: ```#{env.get("preferences").as(Preferences).to_json}```) issue_template += %(\nBacktrace: \n```\n#{exception.inspect_with_backtrace}```) error_message = <<-END_HTML Looks like you've found a bug in Invidious. Please open a new issue on GitHub and include the following text in your message:
#{issue_template}END_HTML return templated "error" end def error_template_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String) env.response.status_code = status_code error_message = translate(locale, message) return templated "error" end macro error_atom(*args) error_atom_helper(env, config, locale, {{*args}}) end def error_atom_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception) if exception.is_a?(InfoException) return error_atom_helper(env, config, locale, status_code, exception.message || "") end env.response.content_type = "application/atom+xml" env.response.status_code = status_code return "