Exception: BWAPI::BWError
- Inherits:
-
StandardError
- Object
- StandardError
- BWAPI::BWError
- Defined in:
- lib/bwapi/error.rb
Overview
BW error class to capture BWAPI error responses
Direct Known Subclasses
BadGateway, BadRequest, Forbidden, InternalServerError, NotAcceptable, NotFound, NotImplemented, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity
Instance Method Summary collapse
-
#determine_errors(response) ⇒ Object
Determines from response and returns error(s).
-
#generate_error_messages(errors_object) ⇒ Object
Generates error messsages based on error object passed.
-
#initialize(response = nil) ⇒ BWError
constructor
A new instance of BWError.
-
#split_array_errors(array) ⇒ Object
Iterates through errors in array.
-
#split_hash_errors(hash) ⇒ Object
Iterates through errors in hash.
-
#verify_object_class(object) ⇒ Object
Verifies objects class.
Constructor Details
#initialize(response = nil) ⇒ BWError
Returns a new instance of BWError.
5 6 7 8 9 |
# File 'lib/bwapi/error.rb', line 5 def initialize response = nil errors_object = determine_errors(response) super() if errors_object.nil? super((errors_object)) end |
Instance Method Details
#determine_errors(response) ⇒ Object
Determines from response and returns error(s)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bwapi/error.rb', line 12 def determine_errors response return nil if response.nil? return nil unless response.is_a?(Hash) && response.has_key?(:body) return nil unless response[:body].is_a?(Hash) # Determine if response body has known error keys and return if response[:body].has_key?('error') && response[:body].has_key?('error_description') return response[:body] elsif response[:body].has_key?('errors') return response[:body]['errors'] else return nil end end |
#generate_error_messages(errors_object) ⇒ Object
Generates error messsages based on error object passed
30 31 32 33 34 |
# File 'lib/bwapi/error.rb', line 30 def errors_object = [] verify_object_class errors_object return .join(', ') end |
#split_array_errors(array) ⇒ Object
Iterates through errors in array
53 54 55 56 57 |
# File 'lib/bwapi/error.rb', line 53 def split_array_errors array array.each_with_index do |e, i| verify_object_class array[i] end end |
#split_hash_errors(hash) ⇒ Object
Iterates through errors in hash
62 63 64 65 66 |
# File 'lib/bwapi/error.rb', line 62 def split_hash_errors hash = [] hash.each {|k,v| << "%s: %s" % [k, v]} << .flatten.join(' with ') end |
#verify_object_class(object) ⇒ Object
Verifies objects class
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bwapi/error.rb', line 39 def verify_object_class object case object when Array split_array_errors(object) when Hash, Hashie::Mash split_hash_errors(object) when String << object end end |