Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
# - ActionController::RoutingError
# - ActionController::UnknownFormat
# - ActionController::UnknownHttpMethod
# - ActionDispatch::Http::MimeNegotiation::InvalidType
# - ActionDispatch::Http::Parameters::ParseError
# - ActiveRecord::RecordNotFound
# - ActiveRecord::RecordNotUnique
Expand Down
1 change: 1 addition & 0 deletions posthog-rails/lib/posthog/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def default_excluded_exceptions
'ActionController::RoutingError',
'ActionController::UnknownFormat',
'ActionController::UnknownHttpMethod',
'ActionDispatch::Http::MimeNegotiation::InvalidType',
'ActionDispatch::Http::Parameters::ParseError',
'ActiveRecord::RecordNotFound',
'ActiveRecord::RecordNotUnique'
Expand Down
42 changes: 42 additions & 0 deletions spec/posthog/rails/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require 'spec_helper'
require 'action_controller'
require 'action_dispatch'

$LOAD_PATH.unshift File.expand_path('../../../posthog-rails/lib', __dir__)

require 'posthog/rails/configuration'

RSpec.describe PostHog::Rails::Configuration do
subject(:config) { described_class.new }

describe '#should_capture_exception?' do
# MimeNegotiation::InvalidType is raised when a client sends a malformed
# Accept / Content-Type header (typically scanner traffic). Rails maps it
# to a 406 — see ActionDispatch::ExceptionWrapper.rescue_responses — so it
# is not a bug worth capturing.
{
'ActionController::RoutingError' => ActionController::RoutingError.new('No route matches'),
'ActionDispatch::Http::MimeNegotiation::InvalidType' =>
ActionDispatch::Http::MimeNegotiation::InvalidType.new('"foo" is not a valid MIME type')
}.each do |name, exception|
it "excludes #{name} by default" do
expect(config.should_capture_exception?(exception)).to be false
end
end

it 'captures application exceptions that are not in the excluded list' do
exception = StandardError.new('something broke')
expect(config.should_capture_exception?(exception)).to be true
end

it 'honours user-supplied excluded_exceptions in addition to defaults' do
config.excluded_exceptions = ['MyApp::IgnorableError']
stub_const('MyApp::IgnorableError', Class.new(StandardError))
expect(config.should_capture_exception?(MyApp::IgnorableError.new)).to be false
# defaults still apply
expect(config.should_capture_exception?(ActionController::RoutingError.new('x'))).to be false
end
end
end