diff --git a/lib/bandwidth_iris_patch.rb b/lib/bandwidth_iris_patch.rb index 5b7f83cb6f2e05ec4ba925847b280d725d1068d5..ed1b1ee617036116ccbc7ce0c6153bb37d9a16be 100644 --- a/lib/bandwidth_iris_patch.rb +++ b/lib/bandwidth_iris_patch.rb @@ -12,12 +12,22 @@ module BandwidthIris end end + class APIErrors < StandardError + attr_reader :errors + + def initialize(errors) + super(errors.map { |e| e[:description] }.join("\n")) + @errors = errors + end + end + class Client # Expose useful error messages from the API instead of hiding them def check_response(response) parsed_body = parse_xml(response.body || "") return parsed_body unless response.status >= 400 - raise APIError.new(**parsed_body[:error]) if parsed_body.key?(:error) + raise APIError.new(**parsed_body[:error]) if parsed_body&.key?(:error) + raise APIErrors, parsed_body[:errors] if parsed_body&.key?(:errors) raise Errors::GenericError.new( "", "Http code #{response.status}", response.status