diff --git a/Gemfile.lock b/Gemfile.lock index 2a1cf30e7d2..c4897db3c4a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -156,7 +156,7 @@ GEM mail (2.6.4) mime-types (>= 1.16, < 4) memory_profiler (0.9.6) - message_bus (2.0.1) + message_bus (2.0.2) rack (>= 1.1.3) metaclass (0.0.4) method_source (0.8.2) diff --git a/config/initializers/004-message_bus.rb b/config/initializers/004-message_bus.rb index 41d5386c5f7..98ae9a51984 100644 --- a/config/initializers/004-message_bus.rb +++ b/config/initializers/004-message_bus.rb @@ -61,6 +61,14 @@ MessageBus.is_admin_lookup do |env| env["__mb"][:is_admin] end +MessageBus.on_middleware_error do |env, e| + if Discourse::InvalidAccess === e + [403, {}, ["Invalid Access"]] + elsif RateLimiter::LimitExceeded === e + [429, {}, [e.description]] + end +end + MessageBus.on_connect do |site_id| RailsMultisite::ConnectionManagement.establish_connection(db: site_id) end