mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 17:04:59 +08:00
DEV: Apply syntax_tree formatting to lib/*
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user