exceptionally 1.4.4 → 1.5.0

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
2
  SHA256:
3
- metadata.gz: ba1c7c909a88df38b73db95b8b1b3a759491c055e2446663d5db20a9af8d8ae6
4
- data.tar.gz: bbb135606b8f05a8fc110244343755bc8b910c6dd4e0924c6d67b705b86d9b0c
3
+ metadata.gz: f9d4a53e48cb1f26ccee7b4cfdff3c4f1fdef4f482860a24aa490e8e666e12c2
4
+ data.tar.gz: ca348946c50cc2248477db81ae54bac7ecb6c7697fbd3d3e1b45046478c9f92d
5
5
  SHA512:
6
- metadata.gz: d50d1d914c77d037f46b288b801e0f25667c2f93cd418a0df3f074004f08b01db2588b452379af0cbcc601d997c5f812fbb4555c7b271e9fd178bce171b09af3
7
- data.tar.gz: ec35da96178d510ccd80b634eccd8bed538c9d1bdb67a88b63a7aa560c95dcc0d64f000c206aee94cef26967265d1556ed8b1ceab2acb77fbcab1f0e0d14d340
6
+ metadata.gz: be4684bb91408431bb4678db6efa568387ba5cdb4447a8587282c2d7f3fc6d20e4fc41cbb800c663a3310959336ffac8574d9dc21133ed4aa286e36315a8c312
7
+ data.tar.gz: 5f8c5efbec8d42941a89cd368d98f85e3c0b4b4af7ba1b53e80e5f4c6ec454cbbda1b042c41a4f95596d279cc5a078d590d1dacf1df68bbdacdd2efd30fe1afb
data/README.md CHANGED
@@ -38,19 +38,11 @@ In addition to seamlessly abstracting your exception logic and returning clean J
38
38
 
39
39
  If you raise a 500-level error, Exceptionally will log the error, backtrace, and relevant parameters to Rails.logger.
40
40
 
41
- ### Error Reporting
42
-
43
- Exceptionally supports reporting 500-level errors to [Sentry](http://getsentry.com), [Airbrake](http://airbrake.io), and [New Relic](http://newrelic.com) out of the box, and will notify those services if you have their gems installed. By default, this is only enabled in your `production` environment, but you can control this by setting in `config/initializers/exceptionally.rb`:
44
-
45
- ```ruby
46
- Exceptionally.report_errors = true
47
- ```
48
-
49
41
  ### Customizable
50
42
 
51
43
  #### Add a custom error handler
52
44
 
53
- Need to add more logging, integrate a different service than those listed above, use [BacktraceCleaner](http://api.rubyonrails.org/classes/ActiveSupport/BacktraceCleaner.html), or do something else with the errors before they're returned to the user? Just add the following to `config/initializers/exceptionally.rb`:
45
+ Need to add more logging, integrate with Sentry, use [BacktraceCleaner](http://api.rubyonrails.org/classes/ActiveSupport/BacktraceCleaner.html), or do something else with the errors before they're returned to the user? Just add the following to `config/initializers/exceptionally.rb`:
54
46
 
55
47
  ```ruby
56
48
  Exceptionally::Handler.before_render do |message, status, error, params|
@@ -90,8 +82,8 @@ Exceptionally will handle the following errors by default:
90
82
  * ArgumentErrors
91
83
  * ActiveRecord::RecordNotFound
92
84
  * ActiveRecord::RecordInvalid
93
- * Apipie::ParamMissing (if using [Apipie](https://github.com/Apipie/apipie-rails))
94
- * Apipie::ParamInvalid (if using [Apipie](https://github.com/Apipie/apipie-rails))
85
+ * ActiveRecord::RecordNotSaved
86
+ * ActionController::ParameterMissing
95
87
  * Exceptionally errors (see below for available errors)
96
88
 
97
89
  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`:
@@ -102,11 +94,11 @@ rescue_from SomeGem::NotAuthorizedError, :with => :not_authorized_error
102
94
 
103
95
  # Tell Exceptionally you want this treated as a 401 error
104
96
  def not_authorized_error(error)
105
- pass_to_error_handler(error, 401)
97
+ pass_to_error_handler(error, 401, {caught_you: true})
106
98
  end
107
99
  ```
108
100
 
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.
101
+ `pass_to_error_handler` takes a Ruby Exception object, a status code, and an optional hash that will be returned in the json by merging it with the error message. If no status code is provided, it will default to 500.
110
102
 
111
103
  ## Available Errors
112
104
 
@@ -144,16 +136,20 @@ You can also raise an error with just the HTTP status code by using `Exceptional
144
136
 
145
137
  ## Why use Exceptionally?
146
138
 
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.
139
+ 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 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.
148
140
 
149
141
  ## Changelog
150
142
 
151
143
  See [changelog](https://github.com/neilgupta/exceptionally/blob/master/CHANGELOG.md) to check for breaking changes between versions.
152
144
 
145
+ ## Development
146
+
147
+ Run tests with `bundle exec rspec`
148
+
153
149
  ## Author
154
150
 
155
151
  Neil Gupta [https://neil.gg](https://neil.gg)
156
152
 
157
153
  ## License
158
154
 
159
- The MIT License (MIT) Copyright (c) 2015 Neil Gupta. See [MIT-LICENSE](https://raw.github.com/neilgupta/exceptionally/master/MIT-LICENSE)
155
+ The MIT License (MIT) Copyright (c) 2023 Neil Gupta. See [MIT-LICENSE](https://raw.github.com/neilgupta/exceptionally/master/MIT-LICENSE)
@@ -10,10 +10,8 @@ module Exceptionally
10
10
  rescue_from Exceptionally::Error, :with => :exceptionally_handler
11
11
  rescue_from ActiveRecord::RecordNotFound, :with => :missing_record_handler
12
12
  rescue_from ActiveRecord::RecordInvalid, :with => :record_invalid_handler
13
- if defined?(Apipie)
14
- rescue_from Apipie::ParamMissing, :with => :missing_param
15
- rescue_from Apipie::ParamInvalid, :with => :invalid_param
16
- end
13
+ rescue_from ActiveRecord::RecordNotSaved, :with => :record_not_saved
14
+ rescue_from ActionController::ParameterMissing, :with => :missing_param_handler
17
15
  end
18
16
 
19
17
  # Raise custom error
@@ -22,7 +20,7 @@ module Exceptionally
22
20
  end
23
21
 
24
22
  # Raise 400 error
25
- def missing_param(error)
23
+ def missing_param_handler(error)
26
24
  pass_to_error_handler(error, 400)
27
25
  end
28
26
 
@@ -37,18 +35,18 @@ module Exceptionally
37
35
  end
38
36
 
39
37
  # Raise 422 error
40
- def invalid_param(error)
41
- pass_to_error_handler(error, 422)
38
+ def record_not_saved(error)
39
+ pass_to_error_handler(error, 422, {validations: error.record.try(:errors)})
42
40
  end
43
41
 
44
- def pass_to_error_handler(error, status = nil)
42
+ def pass_to_error_handler(error, status = nil, extra = {})
45
43
  status ||= error.try(:status) || 500
46
44
  Exceptionally::Handler.new(error.message, status, error, params)
47
- render_error(error, status)
45
+ render_error(error, status, extra)
48
46
  end
49
47
 
50
- def render_error(error, status)
51
- render json: {error: error.message}, status: status
48
+ def render_error(error, status = 500, extra = {})
49
+ render json: {error: error.message}.merge(extra || {}), status: status || 500
52
50
  end
53
51
 
54
52
  end
@@ -23,13 +23,6 @@ module Exceptionally
23
23
  def log
24
24
  # Log 5xx errors
25
25
  if @status >= 500 && @error
26
- # Support Sentry, Airbrake, and New Relic out of box, but only in production
27
- if Exceptionally.report_errors
28
- Raven.capture_exception(@error, {logger: 'Exceptionally', extra: {params: @params}}) if defined?(Raven) && Raven.respond_to?(:capture_exception)
29
- Airbrake.notify(@error, :parameters => @params) if defined?(Airbrake) && Airbrake.respond_to?(:notify)
30
- NewRelic::Agent.notice_error(@error) if defined?(NewRelic) && defined?(NewRelic::Agent) && NewRelic::Agent.respond_to?(:notice_error)
31
- end
32
-
33
26
  Rails.logger.error(@error.to_s)
34
27
  Rails.logger.error("Parameters: #{@params.to_s}") unless @params.blank?
35
28
  Rails.logger.error(@error.backtrace.join("\n")) unless @error.backtrace.blank?
@@ -1,3 +1,3 @@
1
1
  module Exceptionally
2
- VERSION = '1.4.4'.freeze
2
+ VERSION = '1.5.0'.freeze
3
3
  end
data/lib/exceptionally.rb CHANGED
@@ -4,13 +4,4 @@ require 'exceptionally/handler'
4
4
  require 'exceptionally/railtie'
5
5
 
6
6
  module Exceptionally
7
- @@report_errors = Rails.env.production?
8
-
9
- def self.report_errors=(report_errors)
10
- @@report_errors = report_errors
11
- end
12
-
13
- def self.report_errors
14
- @@report_errors
15
- end
16
7
  end
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Version of your assets, change this if you want to expire all your assets.
4
- Rails.application.config.assets.version = '1.0'
4
+ # Rails.application.config.assets.version = '1.0'
5
5
 
6
6
  # Precompile additional assets.
7
7
  # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.