mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	This is the error that is triggering a P0 incident in Chatwoot. ``` DashboardController#index is missing a template for this request format and variant. request.formats: ["application/json"] request.variant: [] ``` The user is calling `/app/accounts/api/v1/accounts/<account-id>/inboxes`. The URL is wrong, the requests are routed to dashboard controller as it starts with `/app/accounts`. The dashboard controller is not handling JSON requests and it creates errors. There are 312k errors over the last 2 years. Close to 50k during last 3 days. This fix would return not_acceptable response to the attempts.
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
require 'rails_helper'
 | 
						|
 | 
						|
describe '/app/login', type: :request do
 | 
						|
  context 'without DEFAULT_LOCALE' do
 | 
						|
    it 'renders the dashboard' do
 | 
						|
      get '/app/login'
 | 
						|
      expect(response).to have_http_status(:success)
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  context 'with DEFAULT_LOCALE' do
 | 
						|
    it 'renders the dashboard' do
 | 
						|
      with_modified_env DEFAULT_LOCALE: 'pt_BR' do
 | 
						|
        get '/app/login'
 | 
						|
        expect(response).to have_http_status(:success)
 | 
						|
        expect(response.body).to include "selectedLocale: 'pt_BR'"
 | 
						|
      end
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  context 'with non-HTML format' do
 | 
						|
    it 'returns not acceptable for JSON' do
 | 
						|
      get '/app/login', params: { format: 'json' }
 | 
						|
      expect(response).to have_http_status(:not_acceptable)
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  # Routes are loaded once on app start
 | 
						|
  # hence Rails.application.reload_routes! is used in this spec
 | 
						|
  # ref : https://stackoverflow.com/a/63584877/939299
 | 
						|
  context 'with CW_API_ONLY_SERVER true' do
 | 
						|
    it 'returns 404' do
 | 
						|
      with_modified_env CW_API_ONLY_SERVER: 'true' do
 | 
						|
        Rails.application.reload_routes!
 | 
						|
        get '/app/login'
 | 
						|
        expect(response).to have_http_status(:not_found)
 | 
						|
      end
 | 
						|
      Rails.application.reload_routes!
 | 
						|
    end
 | 
						|
  end
 | 
						|
end
 |