Skip to content

A platform for community discussion. Free, open, simple.

DEV: Handle InvalidParameters inside bulk action hijack block (#38589)

Isaac Janzen631f51103195
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index 3af51eef940..f57e1495134 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -1129,6 +1129,8 @@ class TopicsController < ApplicationController
result = { topic_ids: changed_topic_ids }
result[:errors] = operator.errors if operator.errors.present?
render_json_dump result
+ rescue Discourse::InvalidParameters => ex
+ render_json_error(ex, status: 400)
end
end
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index b6cafea75f3..296067ae376 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -4337,6 +4337,19 @@ RSpec.describe TopicsController do
expect(response.status).to eq(400)
end
+ it "returns a proper error for an invalid operation type" do
+ put "/topics/bulk.json",
+ params: {
+ topic_ids: topic_ids,
+ operation: {
+ type: "not_a_real_operation",
+ },
+ }
+
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["errors"]).to be_present
+ end
+
it "can dismiss sub-categories posts as read" do
sub = Fabricate(:category, parent_category_id: category.id)