exceptionally 1.2.0 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e77886643295e91bf4a2e09856348134c3c92963
4
- data.tar.gz: c11a2627249286059b11cefa7e4136ad593f254a
2
+ SHA256:
3
+ metadata.gz: e2a92e4f0938ce4c7f74f4f52afeb6d3c59ccf79e31f8b8c6bfab7b6b471c6bf
4
+ data.tar.gz: 154055e1a6a6db7fc4a890f000540d58cae02f4f358857fe514a4e6326e58c7e
5
5
  SHA512:
6
- metadata.gz: 42680626c27ea7700f6328df15ae10508e27d113c370282e903361eb185785dacb1f18c2fb7edd717f3724f7dbc7879ac315f90caf8ee135ffe561d6ffe766a2
7
- data.tar.gz: 0923b8cae35d726ac76d671aa32061e3bd1c87e7a3c4fdf06821f0f13a06da445d9b5a137f7b04f6489e54a8a5c1a9c950a1407bfc51d6a585728e7fc7553857
6
+ metadata.gz: debbfc6ed9668bc19f3267f62b8f15c4d2eda7e892f3c15a128ca11e4639d13db4bdfdad9d3558bb5a0fab3a32741b79cd6f0b7d3e95c7505c16fd62e6b5bc8e
7
+ data.tar.gz: 5a7272c52c64b6dfced6ce8f5a80867fece96bdb9c5d366439fd8714970439fe5e6d42991c54e8778b81779f099ac72feccc0b07694ddbe320ab57d14f8c6f41
data/README.md CHANGED
@@ -73,14 +73,14 @@ end
73
73
  You can also override the returned response by adding a `render_error` method to your controller. For example, if you want to include the HTTP status code in the returned JSON, you can do:
74
74
 
75
75
  ```ruby
76
- def render_error(message, status)
77
- render json: {error_message: message, error_status: status}, status: status
76
+ def render_error(error, status)
77
+ render json: {error_message: error.message, error_status: status}, status: status
78
78
  end
79
79
  ```
80
80
 
81
81
  You could also return HTML, XML, or whatever other format is relevant to your application.
82
82
 
83
- `render_error` must accept `message`, a string description of the error, and `status`, an integer HTTP status code.
83
+ `render_error` must accept `error`, the StandardError object that was raised, and `status`, an integer HTTP status code.
84
84
 
85
85
  #### Add custom errors
86
86
 
@@ -92,22 +92,21 @@ Exceptionally will handle the following errors by default:
92
92
  * ActiveRecord::RecordInvalid
93
93
  * Apipie::ParamMissing (if using [Apipie](https://github.com/Apipie/apipie-rails))
94
94
  * Apipie::ParamInvalid (if using [Apipie](https://github.com/Apipie/apipie-rails))
95
- * Pundit::NotAuthorizedError (if using [Pundit](https://github.com/elabs/pundit))
96
95
  * Exceptionally errors (see below for available errors)
97
96
 
98
97
  If there are additional errors that you want to assign status codes to and pass to Exceptionally, you can add the following to the top of your `application_controller.rb`:
99
98
 
100
99
  ```ruby
101
- # Catch MyCustomModule::BadRequestException errors and pass them to Exceptionally
102
- rescue_from MyCustomModule::BadRequestException, :with => :custom_400_error
100
+ # Catch SomeGem::NotAuthorizedError errors and pass them to Exceptionally
101
+ rescue_from SomeGem::NotAuthorizedError, :with => :not_authorized_error
103
102
 
104
- # Tell Exceptionally you want this treated as a 400 error
105
- def custom_400_error(error)
106
- pass_to_error_handler(error, 400)
103
+ # Tell Exceptionally you want this treated as a 401 error
104
+ def not_authorized_error(error)
105
+ pass_to_error_handler(error, 401)
107
106
  end
108
107
  ```
109
108
 
110
- `pass_to_error_handler` takes a Ruby Exception object and an optional status code. If no status code is provided, it will default to 500.
109
+ `pass_to_error_handler` takes a Ruby Exception object and a status code. If no status code is provided, it will default to 500.
111
110
 
112
111
  ## Available Errors
113
112
 
@@ -147,6 +146,10 @@ You can also raise an error with just the HTTP status code by using `Exceptional
147
146
 
148
147
  By abstracting all of the exception handling logic, Exceptionally DRY's up your code and makes it easier to read. If you later decide to change the format of your error responses, you just need to edit `render_error` in one place. Exceptionally also transparently handles ActiveRecord, Apipie, and other generic exceptions for you, so that your app is less likely to crash. Additionally, you get a bunch of logging and error reporting functionality for free.
149
148
 
149
+ ## Changelog
150
+
151
+ See [changelog](https://github.com/neilgupta/exceptionally/blob/master/CHANGELOG.md) to check for breaking changes between versions.
152
+
150
153
  ## Author
151
154
 
152
155
  Neil Gupta [http://metamorphium.com](http://metamorphium.com)
@@ -14,9 +14,6 @@ module Exceptionally
14
14
  rescue_from Apipie::ParamMissing, :with => :missing_param
15
15
  rescue_from Apipie::ParamInvalid, :with => :invalid_param
16
16
  end
17
- if defined?(Pundit)
18
- rescue_from Pundit::NotAuthorizedError, with: :not_authorized_error
19
- end
20
17
  end
21
18
 
22
19
  # Raise custom error
@@ -29,11 +26,6 @@ module Exceptionally
29
26
  pass_to_error_handler(error, 400)
30
27
  end
31
28
 
32
- # Raise 401 error
33
- def not_authorized_error(error)
34
- pass_to_error_handler(error, 401)
35
- end
36
-
37
29
  # Raise 404 error
38
30
  def missing_record_handler(error)
39
31
  pass_to_error_handler(error, 404)
@@ -43,7 +35,7 @@ module Exceptionally
43
35
  def record_invalid_handler(error)
44
36
  pass_to_error_handler(error, 409)
45
37
  end
46
-
38
+
47
39
  # Raise 422 error
48
40
  def invalid_param(error)
49
41
  pass_to_error_handler(error, 422)
@@ -52,11 +44,11 @@ module Exceptionally
52
44
  def pass_to_error_handler(error, status = nil)
53
45
  status ||= error.try(:status) || 500
54
46
  Exceptionally::Handler.new(error.message, status, error, params)
55
- render_error(error.message, status)
47
+ render_error(error, status)
56
48
  end
57
49
 
58
- def render_error(message, status)
59
- render json: {error: message}, status: status
50
+ def render_error(error, status)
51
+ render json: {error: error.message}, status: status
60
52
  end
61
53
 
62
54
  end
@@ -6,8 +6,11 @@ module Exceptionally
6
6
  @error = e
7
7
  @params = params || {}
8
8
 
9
+ f = ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters)
10
+ @params = f.filter @params
11
+
9
12
  @@callback.call(@message, @status, @error, @params) if defined?(@@callback) && @@callback.respond_to?(:call)
10
-
13
+
11
14
  log
12
15
  end
13
16
 
@@ -1,3 +1,3 @@
1
1
  module Exceptionally
2
- VERSION = "1.2.0"
2
+ VERSION = '1.4.3'.freeze
3
3
  end
@@ -9,6 +9,18 @@ describe ActionController, :type => :controller do
9
9
 
10
10
  before do
11
11
  routes.draw { get 'index' => "anonymous#index" }
12
+ Rails.application.config.filter_parameters = [:password]
13
+ end
14
+
15
+ it 'filters password parameter' do
16
+ temp_params = nil
17
+ Exceptionally::Handler.before_render do |message, status, error, params|
18
+ temp_params = params
19
+ end
20
+
21
+ get :index, username: 'bob', password: '123456'
22
+ expect(temp_params['username']).to eq('bob')
23
+ expect(temp_params['password']).to eq('[FILTERED]')
12
24
  end
13
25
 
14
26
  it 'logs 5xx errors' do
@@ -33,20 +45,20 @@ describe ActionController, :type => :controller do
33
45
  end
34
46
 
35
47
  it 'calls handler before logging an error when set' do
36
- temp_var = nil
48
+ temp_message = nil
37
49
  Exceptionally::Handler.before_render do |message, status, error, params|
38
- temp_var = message
50
+ temp_message = message
39
51
  end
40
52
 
41
53
  get :index
42
- expect(temp_var).to eq('Internal Server Error')
54
+ expect(temp_message).to eq('Internal Server Error')
43
55
  end
44
56
 
45
57
  it 'does not call handler before logging an error when none is proved' do
46
- temp_var = nil
58
+ temp_message = nil
47
59
 
48
60
  get :index
49
- expect(temp_var).to eq(nil)
61
+ expect(temp_message).to eq(nil)
50
62
  end
51
63
 
52
64
  describe 'when only Raven is defined' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptionally
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Gupta
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2020-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 3.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.0'
22
+ version: '7.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 3.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.0'
32
+ version: '7.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec-rails
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +98,7 @@ homepage: https://github.com/neilgupta/exceptionally
98
98
  licenses:
99
99
  - MIT
100
100
  metadata: {}
101
- post_install_message:
101
+ post_install_message:
102
102
  rdoc_options: []
103
103
  require_paths:
104
104
  - lib
@@ -113,45 +113,43 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.4.6
118
- signing_key:
116
+ rubygems_version: 3.0.8
117
+ signing_key:
119
118
  specification_version: 4
120
119
  summary: Exceptionally simple Rails Exception library
121
120
  test_files:
121
+ - spec/spec_helper.rb
122
+ - spec/dummy/app/controllers/application_controller.rb
123
+ - spec/dummy/app/views/layouts/application.html.erb
122
124
  - spec/dummy/app/assets/javascripts/application.js
123
125
  - spec/dummy/app/assets/stylesheets/application.css
124
- - spec/dummy/app/controllers/application_controller.rb
125
126
  - spec/dummy/app/helpers/application_helper.rb
126
- - spec/dummy/app/views/layouts/application.html.erb
127
+ - spec/dummy/bin/rake
127
128
  - spec/dummy/bin/bundle
128
129
  - spec/dummy/bin/rails
129
- - spec/dummy/bin/rake
130
- - spec/dummy/config/application.rb
131
- - spec/dummy/config/boot.rb
132
- - spec/dummy/config/environment.rb
133
- - spec/dummy/config/environments/development.rb
130
+ - spec/dummy/config/secrets.yml
131
+ - spec/dummy/config/routes.rb
132
+ - spec/dummy/config/locales/en.yml
134
133
  - spec/dummy/config/environments/production.rb
134
+ - spec/dummy/config/environments/development.rb
135
135
  - spec/dummy/config/environments/test.rb
136
- - spec/dummy/config/initializers/assets.rb
136
+ - spec/dummy/config/environment.rb
137
+ - spec/dummy/config/application.rb
138
+ - spec/dummy/config/boot.rb
137
139
  - spec/dummy/config/initializers/backtrace_silencers.rb
138
- - spec/dummy/config/initializers/cookies_serializer.rb
139
- - spec/dummy/config/initializers/filter_parameter_logging.rb
140
- - spec/dummy/config/initializers/inflections.rb
141
140
  - spec/dummy/config/initializers/mime_types.rb
141
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
142
142
  - spec/dummy/config/initializers/session_store.rb
143
143
  - spec/dummy/config/initializers/wrap_parameters.rb
144
- - spec/dummy/config/locales/en.yml
145
- - spec/dummy/config/routes.rb
146
- - spec/dummy/config/secrets.yml
144
+ - spec/dummy/config/initializers/assets.rb
145
+ - spec/dummy/config/initializers/cookies_serializer.rb
146
+ - spec/dummy/config/initializers/inflections.rb
147
147
  - spec/dummy/config.ru
148
- - spec/dummy/public/404.html
148
+ - spec/dummy/public/favicon.ico
149
149
  - spec/dummy/public/422.html
150
150
  - spec/dummy/public/500.html
151
- - spec/dummy/public/favicon.ico
151
+ - spec/dummy/public/404.html
152
152
  - spec/dummy/version.rb
153
+ - spec/exceptionally/handler_spec.rb
153
154
  - spec/exceptionally/config_spec.rb
154
155
  - spec/exceptionally/controller_spec.rb
155
- - spec/exceptionally/handler_spec.rb
156
- - spec/spec_helper.rb
157
- has_rdoc: