Exception: Paychex::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Paychex::Error
- Defined in:
- lib/paychex/error.rb
Overview
Custom error class for rescuing from all paychex errors
Direct Known Subclasses
BadGateway, BadRequest, GatewayTimeout, InternalServerError, MissingRequiredArgument, NoAccess, NotFound, ServiceUnavailable, Unauthorized
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#raw_errors ⇒ Object
readonly
Returns the value of attribute raw_errors.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #error_sentence ⇒ Object
-
#initialize(response) ⇒ Error
constructor
A new instance of Error.
- #message ⇒ Object
Constructor Details
#initialize(response) ⇒ Error
Returns a new instance of Error.
6 7 8 9 10 11 12 |
# File 'lib/paychex/error.rb', line 6 def initialize(response) super @response = response.dup @http_method = response.method.to_s @url = response.url @raw_errors = response.body.fetch('errors') if response.body.is_a?(Hash) && !response.body.empty? && !response.body.fetch('errors', nil).nil? end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/paychex/error.rb', line 4 def errors @errors end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
4 5 6 |
# File 'lib/paychex/error.rb', line 4 def http_method @http_method end |
#raw_errors ⇒ Object (readonly)
Returns the value of attribute raw_errors.
4 5 6 |
# File 'lib/paychex/error.rb', line 4 def raw_errors @raw_errors end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/paychex/error.rb', line 4 def response @response end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/paychex/error.rb', line 4 def url @url end |
Instance Method Details
#error_sentence ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/paychex/error.rb', line 23 def error_sentence return if @raw_errors.nil? array = [] @raw_errors.each do |v| array += "#{v['code']}: #{v['description']}, #{v['resolution']}" end array.join(' ') end |
#message ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/paychex/error.rb', line 14 def <<-HEREDOC URL: #{@response.url} method: #{@response.method} response status: #{@response.status} response body: #{@response.response.body} HEREDOC end |