diff --git a/.gitignore b/.gitignore index aae7f11f..6b7fe9d1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ spec/dummy/db/*.sqlite3 spec/dummy/db/*.sqlite3-journal spec/dummy/log/*.log spec/dummy/tmp/ +.rubocop-https* diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..6651a65c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +inherit_from: + - https://raw.githubusercontent.com/lessonly/rubocop-default-configuration/master/.rubocop.yml diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..84f8feeb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Upcoming Release + +- Any unhandled error is now logged to the configured rails logger by default. You can also now supply a custom callable that will be used to handle those exceptions instead. diff --git a/README.md b/README.md index 10b1863c..9a59afa7 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,20 @@ Sample request: $ 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' ``` +### Error Handling + +By default, scim_rails will output any unhandled exceptions to your configured rails logs. + +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`. + +For example, you might want to notify Honeybadger: + +```ruby +ScimRails.configure do |config| + config.on_error = ->(e) { Honeybadger.notify(e) } +end +``` + ## Contributing ### [Code of Conduct](https://github.com/lessonly/scim_rails/blob/master/CODE_OF_CONDUCT.md) diff --git a/Rakefile b/Rakefile index d390a46a..435cbb33 100644 --- a/Rakefile +++ b/Rakefile @@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end -APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) load 'rails/tasks/engine.rake' diff --git a/app/controllers/concerns/scim_rails/exception_handler.rb b/app/controllers/concerns/scim_rails/exception_handler.rb index 2adf1909..f87cbc0a 100644 --- a/app/controllers/concerns/scim_rails/exception_handler.rb +++ b/app/controllers/concerns/scim_rails/exception_handler.rb @@ -12,12 +12,15 @@ class UnsupportedPatchRequest < StandardError end included do - # StandardError must be ordered _first_ or it will catch all exceptions - # - # TODO: Build a plugin/configuration for error handling so that the - # detailed production errors are logged somewhere if desired. if Rails.env.production? - rescue_from StandardError do + rescue_from StandardError do |exception| + on_error = ScimRails.config.on_error + if on_error.respond_to?(:call) + on_error.call(exception) + else + Rails.logger.error(exception.inspect) + end + json_response( { schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"], diff --git a/bin/rails b/bin/rails index 8c9e7642..a1c2ca26 100755 --- a/bin/rails +++ b/bin/rails @@ -4,6 +4,7 @@ ENGINE_ROOT = File.expand_path('../..', __FILE__) ENGINE_PATH = File.expand_path('../../lib/scim_rails/engine', __FILE__) +APP_PATH = File.expand_path('../../spec/dummy/config/application', __FILE__) # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) diff --git a/lib/scim_rails/config.rb b/lib/scim_rails/config.rb index 5d022b3e..aa4f108b 100644 --- a/lib/scim_rails/config.rb +++ b/lib/scim_rails/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ScimRails class << self def configure @@ -5,22 +7,26 @@ def configure end def config - @_config ||= Config.new + @config ||= Config.new end end + # Class containing configuration of ScimRails class Config - ALGO_NONE = "none".freeze + ALGO_NONE = "none" - attr_accessor \ + attr_writer \ :basic_auth_model, + :mutable_user_attributes_schema, + :scim_users_model + + attr_accessor \ :basic_auth_model_authenticatable_attribute, :basic_auth_model_searchable_attribute, :mutable_user_attributes, - :mutable_user_attributes_schema, + :on_error, :queryable_user_attributes, :scim_users_list_order, - :scim_users_model, :scim_users_scope, :scim_user_prevent_update_on_create, :signing_secret,