mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FIX: Ensure RequestTracker handles bubbled exceptions correctly (#26940)
This can happen for various reasons including rate limiting and middleware bugs. This should resolve the warning we're seeing in the logs ``` RequestTracker.get_data failed : NoMethodError : undefined method `[]' for nil:NilClass ```
This commit is contained in:
@ -816,4 +816,22 @@ RSpec.describe Middleware::RequestTracker do
|
||||
expect(@data[:background_type]).to eq("message-bus-dontchunk")
|
||||
end
|
||||
end
|
||||
|
||||
describe "error handling" do
|
||||
before do
|
||||
@original_logger = Rails.logger
|
||||
Rails.logger = @fake_logger = FakeLogger.new
|
||||
end
|
||||
|
||||
after { Rails.logger = @original_logger }
|
||||
|
||||
it "logs requests even if they cause exceptions" do
|
||||
app = lambda { |env| raise RateLimiter::LimitExceeded, 1 }
|
||||
tracker = Middleware::RequestTracker.new(app)
|
||||
expect { tracker.call(env) }.to raise_error(RateLimiter::LimitExceeded)
|
||||
CachedCounting.flush
|
||||
expect(ApplicationRequest.stats).to include("http_total_total" => 1)
|
||||
expect(@fake_logger.warnings).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user