Skip to content

Commit b0ff636

Browse files
Earlopainbyroot
authored andcommitted
Handle Rack 3.2 unprocessable_{entity,content}
Using `unprocessable_entity` will emit a warning on Rack 3.2. There have been various PRs in the past for this: * rails#52252 * rails#52192 * rails#52087 * rails#52097 This to me seems like the least invasive change and is also how headers are currently handled.
1 parent 589fe8a commit b0ff636

File tree

17 files changed

+29
-28
lines changed

17 files changed

+29
-28
lines changed

actionmailbox/app/controllers/action_mailbox/ingresses/mandrill/inbound_emails_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def create
2222
head :ok
2323
rescue JSON::ParserError => error
2424
logger.error error.message
25-
head :unprocessable_entity
25+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
2626
end
2727

2828
def health_check

actionmailbox/app/controllers/action_mailbox/ingresses/postmark/inbound_emails_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def create
5757
When configuring your Postmark inbound webhook, be sure to check the box
5858
labeled "Include raw email content in JSON payload".
5959
MESSAGE
60-
head :unprocessable_entity
60+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
6161
end
6262

6363
private

actionmailbox/app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def create
5555
if request.body
5656
ActionMailbox::InboundEmail.create_and_extract_message_id! request.body.read
5757
else
58-
head :unprocessable_entity
58+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
5959
end
6060
end
6161

actionmailbox/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def create
5252
ActionMailbox::InboundEmail.create_and_extract_message_id! mail
5353
rescue JSON::ParserError => error
5454
logger.error error.message
55-
head :unprocessable_entity
55+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
5656
end
5757

5858
private

actionmailbox/test/controllers/ingresses/postmark/inbound_emails_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ActionMailbox::Ingresses::Postmark::InboundEmailsControllerTest < ActionDi
5353
headers: { authorization: credentials }, params: { From: "[email protected]" }
5454
end
5555

56-
assert_response :unprocessable_entity
56+
assert_response ActionDispatch::Constants::UNPROCESSABLE_CONTENT
5757
end
5858

5959
test "rejecting an unauthorized inbound email from Postmark" do

actionmailbox/test/controllers/ingresses/relay/inbound_emails_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ActionMailbox::Ingresses::Relay::InboundEmailsControllerTest < ActionDispa
3737
env: { "rack.input" => nil }
3838
end
3939

40-
assert_response :unprocessable_entity
40+
assert_response ActionDispatch::Constants::UNPROCESSABLE_CONTENT
4141
end
4242

4343
test "rejecting an unauthorized inbound email" do

actionpack/lib/action_dispatch/constants.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ module Constants
3030
SERVER_TIMING = "server-timing"
3131
STRICT_TRANSPORT_SECURITY = "strict-transport-security"
3232
end
33+
34+
if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
35+
UNPROCESSABLE_CONTENT = :unprocessable_entity
36+
else
37+
UNPROCESSABLE_CONTENT = :unprocessable_content
38+
end
3339
end
3440
end

actionpack/lib/action_dispatch/middleware/exception_wrapper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class ExceptionWrapper
1818
"ActionController::UnknownFormat" => :not_acceptable,
1919
"ActionDispatch::Http::MimeNegotiation::InvalidType" => :not_acceptable,
2020
"ActionController::MissingExactTemplate" => :not_acceptable,
21-
"ActionController::InvalidAuthenticityToken" => :unprocessable_entity,
22-
"ActionController::InvalidCrossOriginRequest" => :unprocessable_entity,
21+
"ActionController::InvalidAuthenticityToken" => ActionDispatch::Constants::UNPROCESSABLE_CONTENT,
22+
"ActionController::InvalidCrossOriginRequest" => ActionDispatch::Constants::UNPROCESSABLE_CONTENT,
2323
"ActionDispatch::Http::Parameters::ParseError" => :bad_request,
2424
"ActionController::BadRequest" => :bad_request,
2525
"ActionController::ParameterMissing" => :bad_request,

actionpack/test/controller/rescue_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def deny_access
147147
end
148148

149149
def show_errors(exception)
150-
head :unprocessable_entity
150+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
151151
end
152152
end
153153

@@ -289,12 +289,12 @@ def test_block_rescue_handler_with_argument_as_string
289289

290290
test "rescue when cause has more specific handler than wrapper" do
291291
get :exception_with_more_specific_handler_for_cause
292-
assert_response :unprocessable_entity
292+
assert_response ActionDispatch::Constants::UNPROCESSABLE_CONTENT
293293
end
294294

295295
test "rescue when cause has handler, but wrapper doesn't" do
296296
get :exception_with_no_handler_for_wrapper
297-
assert_response :unprocessable_entity
297+
assert_response ActionDispatch::Constants::UNPROCESSABLE_CONTENT
298298
end
299299

300300
test "can rescue a ParseError" do

actionpack/test/dispatch/debug_exceptions_test.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def call(env)
8686
raise ActionController::UnknownHttpMethod
8787
when "/not_implemented"
8888
raise ActionController::NotImplemented
89-
when "/unprocessable_entity"
90-
raise ActionController::InvalidAuthenticityToken
9189
when "/invalid_mimetype"
9290
raise ActionDispatch::Http::MimeNegotiation::InvalidType
9391
when "/not_found_original_exception"

0 commit comments

Comments
 (0)