From e79f7d1406d0f701cdc214fcf9fff2009ae51c8e Mon Sep 17 00:00:00 2001 From: Tadas Tamosauskas Date: Mon, 4 Nov 2024 17:37:56 +0000 Subject: [PATCH] Do not load middleware that's not configured in Sinatra 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