fnando / browser

Do some browser detection with Ruby. Includes ActionController integration.
MIT License
2.44k stars 358 forks source link

Question: Suggested way to handle Browser::Error #518

Closed rocket-turtle closed 3 years ago

rocket-turtle commented 3 years ago

Hi, there was a new Exception introduced with this Issue: https://github.com/fnando/browser/pull/493

So I would be interessted in how you handle this Exception.

I included this into the Controller: https://github.com/fnando/browser/blob/main/lib/browser/action_controller.rb

Possibility 1: ignore the Exception browser.ie? Cons: Might get an exception in the prod System.

Possibility 2: rescue the Exception browser.ie? rescue false Cons: Musst be placed everywhere.

Possibility 3: increase user_agent_size_limit to Server Limit https://github.com/fnando/browser/pull/500#issuecomment-703029580 Cons: Need to know the Server Limit, might be big.

Possibility 4: Monkey patch Browser.new Monkey patch Browser.new to allways reduce ua to user_agent_size_limit Cons: Monkey patch

Possibility 5: ??? Other ideas

Thank you for your time.

fnando commented 3 years ago

In Rails, I'd definitely go with rescue_from(Browser::Error, &block) on ApplicationController, returning a 400 status.

Are you getting errors from legit users?

rocket-turtle commented 3 years ago

Im just updating to the new version and was curios because there was nothing in the docs.

Thank you for your suggestion. I'm going to rescue the Exception.