Exception: Apruve::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Apruve::Error
- Defined in:
- lib/apruve/error.rb
Overview
Custom error class for rescuing from all API response-related Apruve errors
Direct Known Subclasses
AccessDenied, BadGateway, BadRequest, Conflict, Forbidden, GatewayTimeout, Gone, InternalServerError, MethodNotAllowed, NotFound, NotImplemented, ResponseUnreadable, ServiceUnavailable, ServiceUnreachable, StandardError, Unauthorized, UnknownError
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #body ⇒ Hash
- #error_message ⇒ Object
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
8 9 10 11 12 13 14 |
# File 'lib/apruve/error.rb', line 8 def initialize(response=nil) @response = response unless response.nil? super # super 'Error!' end end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/apruve/error.rb', line 5 def response @response end |
Instance Method Details
#body ⇒ Hash
17 18 19 20 21 22 |
# File 'lib/apruve/error.rb', line 17 def body @body ||= begin return {} unless response[:body] Utils.indifferent_read_access(response[:body]) end end |
#error_message ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/apruve/error.rb', line 24 def # set_attrs errors = body.fetch('errors', nil) unless errors.nil? error = errors[0] extra = error[:source] ? " -- #{error[:source][:parameter]}" : "" extra += error[:detail] ? " -- #{error[:detail]}" : "" "#{self.class.name}(#{response[:status]}):: "\ "#{response[:method].to_s.upcase} #{response[:url].to_s}: "\ "#{error[:title]} #{extra}" end end |