exceptionally 1.0.0 → 1.0.1

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
  SHA1:
3
- metadata.gz: 021bc161718c3f6759f35966d9d833adfcd9b700
4
- data.tar.gz: c77c028c2e5aefaa9d424910b1898e141b350f63
3
+ metadata.gz: f5d52c4f55cb4c33ac54fd123000ad5ba8fe3f83
4
+ data.tar.gz: e97c1136715699b0e89a3dcc3308117f7e07c4e3
5
5
  SHA512:
6
- metadata.gz: ab99856b766aecb5504bdbbb8fb033f868a40bfca10f751ea3f1d2f420206b68bf92b5bbe1b8a5538c41765f870cdc758d40d34748420e8cbeab42a83eddec31
7
- data.tar.gz: d75cc2385e01a7280fa3602063c92101d174ea375d399df523f41f4394c72cfed30f6168257b0b0f3971ec439d9fee9b9195665c4ae5e7839b5745b9ce44dd5c
6
+ metadata.gz: 6652982d9c887a4c70599a3b61f08623f06b63badc1e5517f5f6d5463f9bb2a3b7e260a0f5cadc4fcc1e16e3df3248a71c9ea9ee1043c35c726a8221fae90f06
7
+ data.tar.gz: be9a538d861e564f7358b3c86d728e9e37ee18f4a4c0dc3af2b82e8bddf40f04aaed57d62c8e2c6ee218d7f566699cc7e463bf63c587b504d87a1dc609bf994c
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [https://www.github.com/neilgupta/exceptionally](https://www.github.com/neilgupta/exceptionally)
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/exceptionally.png)](http://badge.fury.io/rb/exceptionally)
6
+
5
7
  Exceptionally abstracts your exception logic to make raising and returning meaningful errors in Ruby on Rails easier. It is primarily designed for API-only applications that need to return descriptive JSON error messages, rather than static HTML error pages.
6
8
 
7
9
  Just raise the appropriate exception anywhere in your code and Exceptionally will handle the rest.
@@ -34,21 +36,27 @@ In addition to seamlessly abstracting your exception logic and returning clean J
34
36
 
35
37
  ### Logging
36
38
 
37
- If you raise a 500-level error, Exceptionally will log the error, stacktrace, and relevant parameters to Rails.logger. Additionally, Exceptionally supports [Airbrake](http://airbrake.io) and [New Relic](http://newrelic.com) by default, and will notify those services if you have their gems set up.
39
+ If you raise a 500-level error, Exceptionally will log the error, backtrace, and relevant parameters to Rails.logger. Additionally, Exceptionally supports [Airbrake](http://airbrake.io) and [New Relic](http://newrelic.com) by default, and will notify those services if you have their gems set up.
38
40
 
39
41
  ### Customizable
40
42
 
41
43
  #### Add a custom error handler
42
44
 
43
- Need to run your own logging code 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, 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`:
44
46
 
45
47
  ```ruby
46
48
  Exceptionally::Handler.before_render do |message, status, error, params|
47
49
  # Place your custom code here
48
50
  # message is a string description of what went wrong
49
51
  # status is an integer of the HTTP status code
50
- # error is a Ruby Exception object
52
+ # error is the Exception object
51
53
  # params is a hash of the parameters passed to your controller
54
+
55
+ # For example, you could:
56
+ bc = BacktraceCleaner.new
57
+ bc.add_filter { |line| line.gsub(Rails.root, '') }
58
+ bc.add_silencer { |line| line =~ /mongrel|rubygems/ }
59
+ bc.clean(error.backtrace) # will strip the Rails.root prefix and skip any lines from mongrel or rubygems from your backtrace
52
60
  end
53
61
  ```
54
62
 
@@ -114,6 +122,7 @@ You can raise the following HTTP errors. All of them accept an optional string t
114
122
  * Exceptionally::UnsupportedMedia
115
123
  * Exceptionally::RangeNotSatisfiable
116
124
  * Exceptionally::ExpectationFailed
125
+ * Exceptionally::UnprocessableEntity
117
126
  * Exceptionally::Error
118
127
  * Exceptionally::NotImplemented
119
128
  * Exceptionally::BadGateway
@@ -121,11 +130,11 @@ You can raise the following HTTP errors. All of them accept an optional string t
121
130
  * Exceptionally::GatewayTimeout
122
131
  * Exceptionally::HttpVersionNotSupported
123
132
 
124
- You can also raise an error with just the HTTP status code by using `Exceptionally::Http404`. Status codes 400-417 and 500-505 are available.
133
+ You can also raise an error with just the HTTP status code by using `Exceptionally::Http404`. Status codes 400-417, 422, and 500-505 are available.
125
134
 
126
135
  **[See descriptions of all status codes](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)**
127
136
 
128
- ## Why use Exceptionally instead of the built-in Rails `render`?
137
+ ## Why use Exceptionally?
129
138
 
130
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, 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.
131
140
 
@@ -135,4 +144,4 @@ Neil Gupta [http://metamorphium.com](http://metamorphium.com)
135
144
 
136
145
  ## License
137
146
 
138
- The MIT License (MIT) Copyright (c) 2014 Neil Gupta. See [MIT-LICENSE](https://raw.github.com/neilgupta/exceptionally/master/MIT-LICENSE)
147
+ The MIT License (MIT) Copyright (c) 2014 Neil Gupta. See [MIT-LICENSE](https://raw.github.com/neilgupta/exceptionally/master/MIT-LICENSE)
@@ -12,7 +12,7 @@ module Exceptionally
12
12
  rescue_from ActiveRecord::RecordInvalid, :with => :record_invalid_handler
13
13
  if defined?(Apipie)
14
14
  rescue_from Apipie::ParamMissing, :with => :missing_param
15
- rescue_from Apipie::ParamInvalid, :with => :missing_param
15
+ rescue_from Apipie::ParamInvalid, :with => :invalid_param
16
16
  end
17
17
  end
18
18
 
@@ -35,6 +35,11 @@ module Exceptionally
35
35
  def record_invalid_handler(error)
36
36
  pass_to_error_handler(error, 409)
37
37
  end
38
+
39
+ # Raise 422 error
40
+ def invalid_param(error)
41
+ pass_to_error_handler(error, 422)
42
+ end
38
43
 
39
44
  def pass_to_error_handler(error, status = nil)
40
45
  status ||= error.try(:status) || 500
@@ -47,4 +52,4 @@ module Exceptionally
47
52
  end
48
53
 
49
54
  end
50
- end
55
+ end
@@ -125,6 +125,12 @@ module Exceptionally
125
125
  end
126
126
  end
127
127
 
128
+ class UnprocessableEntity < Error
129
+ def initialize(message = nil)
130
+ super(message, 422, "Unprocessable Entity")
131
+ end
132
+ end
133
+
128
134
  class NotImplemented < Error
129
135
  def initialize(message = nil)
130
136
  super(message, 501, "Not Implemented")
@@ -173,10 +179,11 @@ module Exceptionally
173
179
  class Http415 < UnsupportedMedia; end
174
180
  class Http416 < RangeNotSatisfiable; end
175
181
  class Http417 < ExpectationFailed; end
182
+ class Http422 < UnprocessableEntity; end
176
183
  class Http500 < Error; end
177
184
  class Http501 < NotImplemented; end
178
185
  class Http502 < BadGateway; end
179
186
  class Http503 < ServiceUnavailable; end
180
187
  class Http504 < GatewayTimeout; end
181
188
  class Http505 < HttpVersionNotSupported; end
182
- end
189
+ end
@@ -17,9 +17,11 @@ module Exceptionally
17
17
  def log
18
18
  # Log 5xx errors
19
19
  if @status >= 500 && @error
20
- # Support Airbrake and New Relic out of box
21
- Airbrake.notify(@error, :parameters => @params) if defined?(Airbrake) && Airbrake.respond_to?(:notify) && Rails.env.production?
22
- NewRelic::Agent.notice_error(@error) if defined?(NewRelic) && defined?(NewRelic::Agent) && NewRelic::Agent.respond_to?(:notice_error) && Rails.env.production?
20
+ # Support Airbrake and New Relic out of box, but only in production
21
+ if Rails.env.production?
22
+ Airbrake.notify(@error, :parameters => @params) if defined?(Airbrake) && Airbrake.respond_to?(:notify)
23
+ NewRelic::Agent.notice_error(@error) if defined?(NewRelic) && defined?(NewRelic::Agent) && NewRelic::Agent.respond_to?(:notice_error)
24
+ end
23
25
 
24
26
  Rails.logger.error(@error.to_s)
25
27
  Rails.logger.error("Parameters: #{@params.to_s}") unless @params.blank?
@@ -27,4 +29,4 @@ module Exceptionally
27
29
  end
28
30
  end
29
31
  end
30
- end
32
+ end
@@ -6,4 +6,4 @@ module Exceptionally
6
6
  end
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Exceptionally
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Gupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-17 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.4.6
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Exceptionally simple Rails Exception library
@@ -138,3 +138,4 @@ test_files:
138
138
  - test/dummy/README.rdoc
139
139
  - test/exceptionally_test.rb
140
140
  - test/test_helper.rb
141
+ has_rdoc: