Skip to content

Commit

Permalink
FIX: improve error results for message bus failures
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Aug 25, 2016
1 parent bfefda0 commit 846a08d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/004-message_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def setup_message_bus_env(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
Expand Down

0 comments on commit 846a08d

Please sign in to comment.