DEV: Apply syntax_tree formatting to lib/*

This commit is contained in:
David Taylor
2023-01-09 12:10:19 +00:00
parent b0fda61a8e
commit 6417173082
507 changed files with 16550 additions and 12627 deletions

View File

@ -4,11 +4,14 @@
# we need to handle certain exceptions here
module Middleware
class DiscoursePublicExceptions < ::ActionDispatch::PublicExceptions
INVALID_REQUEST_ERRORS = Set.new([
Rack::QueryParser::InvalidParameterError,
ActionController::BadRequest,
ActionDispatch::Http::Parameters::ParseError,
])
INVALID_REQUEST_ERRORS =
Set.new(
[
Rack::QueryParser::InvalidParameterError,
ActionController::BadRequest,
ActionDispatch::Http::Parameters::ParseError,
],
)
def initialize(path)
super
@ -35,31 +38,38 @@ module Middleware
begin
request.format
rescue Mime::Type::InvalidMimeType
return [400, { "Cache-Control" => "private, max-age=0, must-revalidate" }, ["Invalid MIME type"]]
return [
400,
{ "Cache-Control" => "private, max-age=0, must-revalidate" },
["Invalid MIME type"]
]
end
# Or badly formatted multipart requests
begin
request.POST
rescue EOFError
return [400, { "Cache-Control" => "private, max-age=0, must-revalidate" }, ["Invalid request"]]
return [
400,
{ "Cache-Control" => "private, max-age=0, must-revalidate" },
["Invalid request"]
]
end
if ApplicationController.rescue_with_handler(exception, object: fake_controller)
body = response.body
if String === body
body = [body]
end
return [response.status, response.headers, body]
body = [body] if String === body
return response.status, response.headers, body
end
rescue => e
return super if INVALID_REQUEST_ERRORS.include?(e.class)
Discourse.warn_exception(e, message: "Failed to handle exception in exception app middleware")
Discourse.warn_exception(
e,
message: "Failed to handle exception in exception app middleware",
)
end
end
super
end
end
end