Skip to content

Commit 2d06f42

Browse files
committed
Port the public exceptions injection
Instead of making every app using our gem insert our custom middleware, we just load it for them. The standard hook to do this is via a railtie. We load the railtie when the gem is loaded and we detect we are in a Rails environment. Rails will do this in the standard `config/application.rb` when it loads all the gems.
1 parent 8a0252b commit 2d06f42

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/kracken.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require "kracken/credential_authenticator"
1010
require "kracken/authenticator"
1111
require "kracken/registration"
12+
require "kracken/railtie" if defined?(Rails)
1213

1314
module Kracken
1415
mattr_accessor :config

lib/kracken/railtie.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "kracken/json_api"
2+
3+
module Kracken
4+
# Railtie to hook into Rails.
5+
class Railtie < ::Rails::Railtie
6+
initializer "kracken.json_api.public_exceptions" do |app|
7+
app.middleware.insert_after ActionDispatch::DebugExceptions,
8+
::Kracken::JsonApi::PublicExceptions
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)