From d84c2b15f61b1a019be6329981d8f5323115d1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadas=20Tamo=C5=A1auskas?= <218239+tadast@users.noreply.github.com> Date: Tue, 5 Nov 2024 19:48:22 +0000 Subject: [PATCH] fix: don't run middleware in Sinatra when not configured (#629) While https://github.com/honeybadger-io/honeybadger-ruby/pull/549 has removed middleware loading for Rails unless configured, it has also removed the code that prevented the middleware from executing unless configured. A similar change is also required for Sinatra, because currently it tries to execute when not configured. When a Sinatra app does not use i18n gem and has user feedback disabled, it errs with a "I18n::InvalidLocale - :en is not a valid locale" exception from ERB, because Honeybadger tries to render the feedback form. --- lib/honeybadger/init/sinatra.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/honeybadger/init/sinatra.rb b/lib/honeybadger/init/sinatra.rb index ca52b1fd..6cb8923e 100644 --- a/lib/honeybadger/init/sinatra.rb +++ b/lib/honeybadger/init/sinatra.rb @@ -31,8 +31,8 @@ def install_honeybadger if config[:'exceptions.enabled'] # These two must come before the ErrorNotifier, since an error/response # passes through middleware from inner to outer (bottom to top) - install_honeybadger_middleware(Honeybadger::Rack::UserFeedback) - install_honeybadger_middleware(Honeybadger::Rack::UserInformer) + install_honeybadger_middleware(Honeybadger::Rack::UserFeedback) if config[:'feedback.enabled'] + install_honeybadger_middleware(Honeybadger::Rack::UserInformer) if config[:'user_informer.enabled'] install_honeybadger_middleware(Honeybadger::Rack::ErrorNotifier) end end