Skip to content
Snippets Groups Projects
Commit 0e23d1a7 authored by Stan Hu's avatar Stan Hu
Browse files

Handle case when BroadcastMessage.current is nil

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

Closes #35094
parent dbcc0e03
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
{}
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment