Skip to content

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

DEV: correctly returns contract error (#32645)

Joffrey JAFFEUX0947a14284d0
diff --git a/plugins/chat/lib/chat_sdk/thread.rb b/plugins/chat/lib/chat_sdk/thread.rb
index 3422afe7207..324affad913 100644
--- a/plugins/chat/lib/chat_sdk/thread.rb
+++ b/plugins/chat/lib/chat_sdk/thread.rb
@@ -83,6 +83,7 @@ module ChatSDK
},
) do
on_success { |messages:| messages }
+ on_failed_contract { |contract| raise contract.errors.full_messages.join(", ") }
on_failed_policy(:can_view_thread) { raise "Guardian can't view thread" }
on_failed_policy(:target_message_exists) { raise "Target message doesn't exist" }
on_failure { raise "Unexpected error" }
diff --git a/plugins/chat/spec/lib/chat_sdk/thread_spec.rb b/plugins/chat/spec/lib/chat_sdk/thread_spec.rb
index 94438a42017..2483e6f3ffe 100644
--- a/plugins/chat/spec/lib/chat_sdk/thread_spec.rb
+++ b/plugins/chat/spec/lib/chat_sdk/thread_spec.rb
@@ -126,6 +126,14 @@ describe ChatSDK::Thread do
end
end
+ context "when page_size is too large" do
+ it "fails" do
+ expect { described_class.messages(**params, page_size: 9999) }.to raise_error(
+ "Page size must be less than or equal to 50",
+ )
+ end
+ end
+
context "when target_message doesn’t exist" do
it "fails" do
expect { described_class.messages(**params, target_message_id: -999) }.to raise_error(