提交 0e23d1a7 编写于 作者: S Stan Hu

Handle case when BroadcastMessage.current is nil

Somehow Rails.cache.fetch occasionally returns `nil` values, which causes
this endpoint to crash.

Closes #35094
上级 dbcc0e03
......@@ -101,7 +101,7 @@ module API
end
get "/broadcast_message" do
if message = BroadcastMessage.current.last
if message = BroadcastMessage.current&.last
present message, with: Entities::BroadcastMessage
else
{}
......
......@@ -35,6 +35,17 @@ describe API::Internal do
expect(json_response).to be_empty
end
end
context 'nil broadcast message' do
it 'returns nothing' do
allow(BroadcastMessage).to receive(:current).and_return(nil)
get api('/internal/broadcast_message'), secret_token: secret_token
expect(response).to have_http_status(200)
expect(json_response).to be_empty
end
end
end
describe 'GET /internal/broadcast_messages' do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册