Commit e05971b0b98f97e4214035a92d8c7d34a11c6ae7
Committed by
GitHub
Exists in
master
Merge pull request #27 from rreinhardt9/add-error-logging
Add logging for unhandled exceptions
Showing
8 changed files
with
41 additions
and
11 deletions
Show diff stats
.gitignore
README.md
... | ... | @@ -246,6 +246,20 @@ Sample request: |
246 | 246 | $ curl -X PATCH 'http://username:password@localhost:3000/scim/v2/Users/1' -d '{"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], "Operations": [{"op": "replace", "value": { "active": false }}]}' -H 'Content-Type: application/scim+json' |
247 | 247 | ``` |
248 | 248 | |
249 | +### Error Handling | |
250 | + | |
251 | +By default, scim_rails will output any unhandled exceptions to your configured rails logs. | |
252 | + | |
253 | +If you would like, you can supply a custom handler for exceptions in the initializer. The only requirement is that the value you supply responds to `#call`. | |
254 | + | |
255 | +For example, you might want to notify Honeybadger: | |
256 | + | |
257 | +```ruby | |
258 | +ScimRails.configure do |config| | |
259 | + config.on_error = ->(e) { Honeybadger.notify(e) } | |
260 | +end | |
261 | +``` | |
262 | + | |
249 | 263 | ## Contributing |
250 | 264 | |
251 | 265 | ### [Code of Conduct](https://github.com/lessonly/scim_rails/blob/master/CODE_OF_CONDUCT.md) | ... | ... |
Rakefile
... | ... | @@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc| |
14 | 14 | rdoc.rdoc_files.include('lib/**/*.rb') |
15 | 15 | end |
16 | 16 | |
17 | -APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) | |
17 | +APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) | |
18 | 18 | load 'rails/tasks/engine.rake' |
19 | 19 | |
20 | 20 | ... | ... |
app/controllers/concerns/scim_rails/exception_handler.rb
... | ... | @@ -12,12 +12,15 @@ module ScimRails |
12 | 12 | end |
13 | 13 | |
14 | 14 | included do |
15 | - # StandardError must be ordered _first_ or it will catch all exceptions | |
16 | - # | |
17 | - # TODO: Build a plugin/configuration for error handling so that the | |
18 | - # detailed production errors are logged somewhere if desired. | |
19 | 15 | if Rails.env.production? |
20 | - rescue_from StandardError do | |
16 | + rescue_from StandardError do |exception| | |
17 | + on_error = ScimRails.config.on_error | |
18 | + if on_error.respond_to?(:call) | |
19 | + on_error.call(exception) | |
20 | + else | |
21 | + Rails.logger.error(exception.inspect) | |
22 | + end | |
23 | + | |
21 | 24 | json_response( |
22 | 25 | { |
23 | 26 | schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"], | ... | ... |
bin/rails
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | |
5 | 5 | ENGINE_ROOT = File.expand_path('../..', __FILE__) |
6 | 6 | ENGINE_PATH = File.expand_path('../../lib/scim_rails/engine', __FILE__) |
7 | +APP_PATH = File.expand_path('../../spec/dummy/config/application', __FILE__) | |
7 | 8 | |
8 | 9 | # Set up gems listed in the Gemfile. |
9 | 10 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) | ... | ... |
lib/scim_rails/config.rb
1 | +# frozen_string_literal: true | |
2 | + | |
1 | 3 | module ScimRails |
2 | 4 | class << self |
3 | 5 | def configure |
... | ... | @@ -5,22 +7,26 @@ module ScimRails |
5 | 7 | end |
6 | 8 | |
7 | 9 | def config |
8 | - @_config ||= Config.new | |
10 | + @config ||= Config.new | |
9 | 11 | end |
10 | 12 | end |
11 | 13 | |
14 | + # Class containing configuration of ScimRails | |
12 | 15 | class Config |
13 | - ALGO_NONE = "none".freeze | |
16 | + ALGO_NONE = "none" | |
14 | 17 | |
15 | - attr_accessor \ | |
18 | + attr_writer \ | |
16 | 19 | :basic_auth_model, |
20 | + :mutable_user_attributes_schema, | |
21 | + :scim_users_model | |
22 | + | |
23 | + attr_accessor \ | |
17 | 24 | :basic_auth_model_authenticatable_attribute, |
18 | 25 | :basic_auth_model_searchable_attribute, |
19 | 26 | :mutable_user_attributes, |
20 | - :mutable_user_attributes_schema, | |
27 | + :on_error, | |
21 | 28 | :queryable_user_attributes, |
22 | 29 | :scim_users_list_order, |
23 | - :scim_users_model, | |
24 | 30 | :scim_users_scope, |
25 | 31 | :scim_user_prevent_update_on_create, |
26 | 32 | :signing_secret, | ... | ... |