Handle case when BroadcastMessage.current is nil
Somehow Rails.cache.fetch occasionally returns `nil` values, which causes this endpoint to crash. Closes #35094
This commit is contained in:
		
							parent
							
								
									dbcc0e03ac
								
							
						
					
					
						commit
						0e23d1a74f
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue