Skip to content

fix(rails): exclude MimeNegotiation::InvalidType by default#160

Open
moladukes wants to merge 2 commits into
PostHog:mainfrom
moladukes:fix/exclude-mime-negotiation-invalidtype
Open

fix(rails): exclude MimeNegotiation::InvalidType by default#160
moladukes wants to merge 2 commits into
PostHog:mainfrom
moladukes:fix/exclude-mime-negotiation-invalidtype

Conversation

@moladukes
Copy link
Copy Markdown

@moladukes moladukes commented May 28, 2026

Closes #159.

MimeNegotiation::InvalidType is raised when a client sends a malformed Accept / Content-Type header, almost always scanner traffic. Rails maps it to a 406 via ActionDispatch::ExceptionWrapper.rescue_responses, so it's not an app bug. Same category as the already-excluded BadRequest / UnknownFormat / ParseError.

  • Adds the class to default_excluded_exceptions
  • Updates the generator template's docs
  • Adds spec/posthog/rails/configuration_spec.rb

bundle exec rspec and bundle exec rubocop pass locally.

Raised when a client sends a malformed Accept or Content-Type header
(typically scanner/fuzzer traffic). Rails maps it to a 406 via
ActionDispatch::ExceptionWrapper.rescue_responses, so it is not an
application bug worth capturing.
@moladukes moladukes requested a review from a team as a code owner May 28, 2026 12:10
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 28, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
spec/posthog/rails/configuration_spec.rb:15-27
The team's coding standard prefers parameterised tests. The two "excludes … by default" examples are identical in structure and are ideal candidates for a shared iteration. A loop-based approach also makes it trivial to extend coverage to every class in `default_excluded_exceptions` without repeating the expectation.

```suggestion
    {
      '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
```

Reviews (1): Last reviewed commit: "fix(rails): exclude MimeNegotiation::Inv..." | Re-trigger Greptile

Comment on lines +15 to +27
it 'excludes ActionController::RoutingError by default' do
exception = ActionController::RoutingError.new('No route matches')
expect(config.should_capture_exception?(exception)).to be false
end

it 'excludes ActionDispatch::Http::MimeNegotiation::InvalidType by default' do
# 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.
exception = ActionDispatch::Http::MimeNegotiation::InvalidType.new('"foo" is not a valid MIME type')
expect(config.should_capture_exception?(exception)).to be false
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The team's coding standard prefers parameterised tests. The two "excludes … by default" examples are identical in structure and are ideal candidates for a shared iteration. A loop-based approach also makes it trivial to extend coverage to every class in default_excluded_exceptions without repeating the expectation.

Suggested change
it 'excludes ActionController::RoutingError by default' do
exception = ActionController::RoutingError.new('No route matches')
expect(config.should_capture_exception?(exception)).to be false
end
it 'excludes ActionDispatch::Http::MimeNegotiation::InvalidType by default' do
# 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.
exception = ActionDispatch::Http::MimeNegotiation::InvalidType.new('"foo" is not a valid MIME type')
expect(config.should_capture_exception?(exception)).to be false
end
{
'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
Prompt To Fix With AI
This is a comment left during a code review.
Path: spec/posthog/rails/configuration_spec.rb
Line: 15-27

Comment:
The team's coding standard prefers parameterised tests. The two "excludes … by default" examples are identical in structure and are ideal candidates for a shared iteration. A loop-based approach also makes it trivial to extend coverage to every class in `default_excluded_exceptions` without repeating the expectation.

```suggestion
    {
      '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
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Author

@moladukes moladukes May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in a4027a9 and kept the comment about why InvalidType matters above the hash.

Matches the iteration pattern used elsewhere in the spec suite
(e.g. client_spec.rb:628).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

posthog-rails: exclude ActionDispatch::Http::MimeNegotiation::InvalidType by default

1 participant